Skip to content

Commit

Permalink
fixing issue with key parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
shibme committed Jan 22, 2024
1 parent 0540a62 commit f97aa17
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,31 +117,29 @@ func ParsePublicKey(pubKeyBytes []byte) (*PublicKey, error) {
return nil, errInvalidPublicKey
}
keyType := pubKeyBytes[0]
switch keyType {
case keyTypeEccDirect | keyTypeEccPwd:
keyBytes := pubKeyBytes[1:]
var spec *kdfSpec
if keyType == keyTypeEccPwd {
specBytes := keyBytes[keyLength:]
var err error
if spec, err = parseKdfSpec(specBytes); err != nil {
return nil, err
}
keyBytes = keyBytes[:keyLength]
}
eccPubKey, err := ecc.GetPublicKey(keyBytes)
if err != nil {
if keyType != keyTypeEccDirect && keyType != keyTypeEccPwd {
return nil, errInvalidPublicKey
}
keyBytes := pubKeyBytes[1:]
var spec *kdfSpec
if keyType == keyTypeEccPwd {
specBytes := keyBytes[keyLength:]
var err error
if spec, err = parseKdfSpec(specBytes); err != nil {
return nil, err
}
publicKey := &PublicKey{
keyType: keyType,
publicKey: eccPubKey,
spec: spec,
}
return publicKey, nil
default:
return nil, errInvalidPublicKey
keyBytes = keyBytes[:keyLength]
}
eccPubKey, err := ecc.GetPublicKey(keyBytes)
if err != nil {
return nil, err
}
publicKey := &PublicKey{
keyType: keyType,
publicKey: eccPubKey,
spec: spec,
}
return publicKey, nil
}

func (publicKey *PublicKey) isPwdBased() bool {
Expand Down

0 comments on commit f97aa17

Please sign in to comment.