Unverified Commit 02987888 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #1 from dignifiedquire/feat/key-equals

feat: add Equal method to compare keys
parents 01a7c5e7 80f7894f
Pipeline #407 failed with stages
in 0 seconds
......@@ -85,6 +85,9 @@ type PublicKey interface {
// `KeyType() == KeyTypeRSA2` would both have `BaseType() == KeyTypeRSA`.
BaseType() NID
// Equal compares the key with the passed in key.
Equal(key PublicKey) bool
evpPKey() *C.EVP_PKEY
}
......@@ -109,6 +112,10 @@ type pKey struct {
func (key *pKey) evpPKey() *C.EVP_PKEY { return key.key }
func (key *pKey) Equal(other PublicKey) bool {
return C.EVP_PKEY_cmp(key.key, other.evpPKey()) == 1
}
func (key *pKey) KeyType() NID {
return NID(C.EVP_PKEY_id(key.key))
}
......
......@@ -36,6 +36,10 @@ func TestMarshal(t *testing.T) {
t.Fatal(err)
}
if !key.Equal(key) {
t.Fatal("key not equal to itself")
}
privateBlock, _ := pem_pkg.Decode(keyBytes)
key, err = LoadPrivateKeyFromDER(privateBlock.Bytes)
if err != nil {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment