Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-openssl
Commits
02987888
Unverified
Commit
02987888
authored
Jun 29, 2019
by
Steven Allen
Committed by
GitHub
Jun 29, 2019
Browse files
Options
Browse Files
Download
Plain Diff
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
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
0 deletions
+11
-0
key.go
key.go
+7
-0
key_test.go
key_test.go
+4
-0
No files found.
key.go
View file @
02987888
...
...
@@ -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
))
}
...
...
key_test.go
View file @
02987888
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment