mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 20:26:19 +08:00
Merge pull request #324 from hrimfaxi/main
sm9: Prevent PublicKey() returning nil after unmarshaling master priavate key
This commit is contained in:
commit
5aacbc2011
@ -114,7 +114,13 @@ func UnmarshalSignMasterPrivateKeyASN1(der []byte) (*SignMasterPrivateKey, error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &SignMasterPrivateKey{privateKey: priv.Bytes(), internal: priv}, nil
|
|
||||||
|
master := &SignMasterPrivateKey{privateKey: priv.Bytes(), internal: priv}
|
||||||
|
master.publicKey = &SignMasterPublicKey{
|
||||||
|
publicKey: priv.PublicKey().Bytes(),
|
||||||
|
internal: priv.PublicKey(),
|
||||||
|
}
|
||||||
|
return master, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateUserKey generate a signature private key for the given user.
|
// GenerateUserKey generate a signature private key for the given user.
|
||||||
@ -370,7 +376,13 @@ func UnmarshalEncryptMasterPrivateKeyASN1(der []byte) (*EncryptMasterPrivateKey,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &EncryptMasterPrivateKey{privateKey: privateKey.Bytes(), internal: privateKey}, nil
|
|
||||||
|
master := &EncryptMasterPrivateKey{privateKey: privateKey.Bytes(), internal: privateKey}
|
||||||
|
master.publicKey = &EncryptMasterPublicKey{
|
||||||
|
publicKey: privateKey.PublicKey().Bytes(),
|
||||||
|
internal: privateKey.PublicKey(),
|
||||||
|
}
|
||||||
|
return master, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equal compares the receiver EncryptMasterPublicKey with another EncryptMasterPublicKey
|
// Equal compares the receiver EncryptMasterPublicKey with another EncryptMasterPublicKey
|
||||||
|
@ -27,6 +27,11 @@ func TestSignMasterPrivateKeyMarshalASN1(t *testing.T) {
|
|||||||
if !masterKey.Equal(masterKey2) {
|
if !masterKey.Equal(masterKey2) {
|
||||||
t.Errorf("expected %v, got %v", hex.EncodeToString(masterKey.Bytes()), hex.EncodeToString(masterKey2.Bytes()))
|
t.Errorf("expected %v, got %v", hex.EncodeToString(masterKey.Bytes()), hex.EncodeToString(masterKey2.Bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
masterPubKey := masterKey2.PublicKey()
|
||||||
|
if masterPubKey == nil {
|
||||||
|
t.Fatal("cannot export public key")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSignMasterPublicKeyMarshalASN1(t *testing.T) {
|
func TestSignMasterPublicKeyMarshalASN1(t *testing.T) {
|
||||||
@ -129,6 +134,11 @@ func TestEncryptMasterPrivateKeyMarshalASN1(t *testing.T) {
|
|||||||
if !masterKey.Equal(masterKey2) {
|
if !masterKey.Equal(masterKey2) {
|
||||||
t.Errorf("expected %v, got %v", hex.EncodeToString(masterKey.Bytes()), hex.EncodeToString(masterKey2.Bytes()))
|
t.Errorf("expected %v, got %v", hex.EncodeToString(masterKey.Bytes()), hex.EncodeToString(masterKey2.Bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
masterPubKey := masterKey2.PublicKey()
|
||||||
|
if masterPubKey == nil {
|
||||||
|
t.Fatal("cannot export public key")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEncryptMasterPublicKeyMarshalASN1(t *testing.T) {
|
func TestEncryptMasterPublicKeyMarshalASN1(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user