diff --git a/routes/pgp.go b/routes/pgp.go index ba8e9bf..2f99ed6 100644 --- a/routes/pgp.go +++ b/routes/pgp.go @@ -1,6 +1,8 @@ package routes import ( + "crypto/ecdsa" + "crypto/rsa" "encoding/hex" "net/http" "time" @@ -17,7 +19,7 @@ type PGPKey struct { CreationTime time.Time PublicKeyAlgorithm packet.PublicKeyAlgorithm Fingerprint [20]byte - KeyID uint16 + KeyID uint64 } func GetOpenPGPInformationEncoded(c *gin.Context) { @@ -57,10 +59,32 @@ func GetOpenPGPInformationEncoded(c *gin.Context) { CreationTime: entity.PrimaryKey.CreationTime, PublicKeyAlgorithm: entity.PrimaryKey.PubKeyAlgo, Fingerprint: entity.PrimaryKey.Fingerprint, - KeyID: uint16(entity.PrimaryKey.KeyId), + KeyID: entity.PrimaryKey.KeyId, } break } + + // bitLength, _ := entity.PrimaryKey.BitLength() + var bitLength int + + switch entity.PrimaryKey.PubKeyAlgo { + case packet.PubKeyAlgoECDSA: + if ecdsaKey, ok := entity.PrimaryKey.PublicKey.(*ecdsa.PublicKey); ok { + bitLength = ecdsaKey.Params().BitSize + } else { + panic("expected ecdsa.PublicKey for type packet.PubKeyAlgoECDSA") + } + case packet.PubKeyAlgoRSA: + if rsaKey, ok := entity.PrimaryKey.PublicKey.(*rsa.PublicKey); ok { + bitLength = rsaKey.N.BitLen() + } else { + panic("expected rsa.PublicKey for type packet.PubKeyAlgoRSA") + } + default: + val, _ := entity.PrimaryKey.BitLength() + bitLength = int(val) + } + c.JSON(http.StatusOK, gin.H{ "status": true, "fullName": key.FullName, @@ -70,6 +94,7 @@ func GetOpenPGPInformationEncoded(c *gin.Context) { "creationTime": key.CreationTime, "publicKeyAlgorithm": key.PublicKeyAlgorithm, "fingerprint": hex.EncodeToString(key.Fingerprint[:]), - "keyID": key.KeyID, + "keyID": entity.PrimaryKey.KeyIdString(), + "bitLength": bitLength, }) }