-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make NIST PublicKey
s conform to Hashable
#176
base: main
Are you sure you want to change the base?
Changes from all commits
a469054
da73315
1d8fd2f
44d04f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,14 @@ extension ${CURVE} { | |
let pemDocument = ASN1.PEMDocument(type: "PUBLIC KEY", derBytes: self.derRepresentation) | ||
return pemDocument.pemString | ||
} | ||
|
||
public static func ==(lhs: Self, rhs: Self) -> Bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Equatable, Part of #174 but I was unable to create a diff between just this PR and the source branch of that PR. |
||
lhs.rawRepresentation == rhs.rawRepresentation | ||
} | ||
|
||
public func hash(into hasher: inout Hasher) { | ||
hasher.combine(rawRepresentation) | ||
} | ||
} | ||
|
||
% if FUNC == "Signing": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,6 +398,138 @@ class SignatureTests: XCTestCase { | |
let compressedX963Positive = Data(base64Encoded: "A+QHCXtGd5WWSQgp37FBPXMy+nnSwFK79QQD0ZeNMv7L")! | ||
XCTAssertThrowsError(try P256.Signing.PublicKey(x963Representation: compressedX963Positive)) | ||
} | ||
|
||
|
||
func testP256SigningPublicKeyEquatable() throws { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Equatable, Part of #174 but I was unable to create a diff between just this PR and the source branch of that PR. |
||
// Equality | ||
let publicKey = P256.Signing.PrivateKey().publicKey | ||
XCTAssertEqual(publicKey, publicKey) | ||
|
||
// Inequality | ||
for _ in 0..<32 { | ||
XCTAssertNotEqual( | ||
publicKey, | ||
P256.Signing.PrivateKey().publicKey | ||
) | ||
} | ||
} | ||
|
||
func testP256KeyAgreementPublicKeyEquatable() throws { | ||
// Equality | ||
let publicKey = P256.KeyAgreement.PrivateKey().publicKey | ||
XCTAssertEqual(publicKey, publicKey) | ||
|
||
// Inequality | ||
for _ in 0..<32 { | ||
XCTAssertNotEqual( | ||
publicKey, | ||
P256.KeyAgreement.PrivateKey().publicKey | ||
) | ||
} | ||
} | ||
|
||
func testP384SigningPublicKeyEquatable() throws { | ||
// Equality | ||
let publicKey = P384.Signing.PrivateKey().publicKey | ||
XCTAssertEqual(publicKey, publicKey) | ||
|
||
// Inequality | ||
for _ in 0..<32 { | ||
XCTAssertNotEqual( | ||
publicKey, | ||
P384.Signing.PrivateKey().publicKey | ||
) | ||
} | ||
} | ||
|
||
func testP384KeyAgreementPublicKeyEquatable() throws { | ||
// Equality | ||
let publicKey = P384.KeyAgreement.PrivateKey().publicKey | ||
XCTAssertEqual(publicKey, publicKey) | ||
|
||
// Inequality | ||
for _ in 0..<32 { | ||
XCTAssertNotEqual( | ||
publicKey, | ||
P384.KeyAgreement.PrivateKey().publicKey | ||
) | ||
} | ||
} | ||
|
||
func testP521SigningPublicKeyEquatable() throws { | ||
// Equality | ||
let publicKey = P521.Signing.PrivateKey().publicKey | ||
XCTAssertEqual(publicKey, publicKey) | ||
|
||
// Inequality | ||
for _ in 0..<32 { | ||
XCTAssertNotEqual( | ||
publicKey, | ||
P521.Signing.PrivateKey().publicKey | ||
) | ||
} | ||
} | ||
|
||
func testP521KeyAgreementPublicKeyEquatable() throws { | ||
// Equality | ||
let publicKey = P521.KeyAgreement.PrivateKey().publicKey | ||
XCTAssertEqual(publicKey, publicKey) | ||
|
||
// Inequality | ||
for _ in 0..<32 { | ||
XCTAssertNotEqual( | ||
publicKey, | ||
P521.KeyAgreement.PrivateKey().publicKey | ||
) | ||
} | ||
} | ||
|
||
func testP256SigningPublicKeyHashable() throws { | ||
let expectedCount = 64 | ||
let set = Set((0..<expectedCount).map { _ in | ||
P256.Signing.PrivateKey().publicKey | ||
}) | ||
XCTAssertEqual(set.count, expectedCount) | ||
} | ||
|
||
func testP256KeyAgreementPublicKeyHashable() throws { | ||
let expectedCount = 64 | ||
let set = Set((0..<expectedCount).map { _ in | ||
P256.KeyAgreement.PrivateKey().publicKey | ||
}) | ||
XCTAssertEqual(set.count, expectedCount) | ||
} | ||
|
||
func testP384SigningPublicKeyHashable() throws { | ||
let expectedCount = 64 | ||
let set = Set((0..<expectedCount).map { _ in | ||
P384.Signing.PrivateKey().publicKey | ||
}) | ||
XCTAssertEqual(set.count, expectedCount) | ||
} | ||
|
||
func testP384KeyAgreementPublicKeyHashable() throws { | ||
let expectedCount = 64 | ||
let set = Set((0..<expectedCount).map { _ in | ||
P384.KeyAgreement.PrivateKey().publicKey | ||
}) | ||
XCTAssertEqual(set.count, expectedCount) | ||
} | ||
|
||
func testP521SigningPublicKeyHashable() throws { | ||
let expectedCount = 64 | ||
let set = Set((0..<expectedCount).map { _ in | ||
P521.Signing.PrivateKey().publicKey | ||
}) | ||
XCTAssertEqual(set.count, expectedCount) | ||
} | ||
|
||
func testP521KeyAgreementPublicKeyHashable() throws { | ||
let expectedCount = 64 | ||
let set = Set((0..<expectedCount).map { _ in | ||
P521.KeyAgreement.PrivateKey().publicKey | ||
}) | ||
XCTAssertEqual(set.count, expectedCount) | ||
} | ||
|
||
} | ||
#endif // (os(macOS) || os(iOS) || os(watchOS) || os(tvOS)) && CRYPTO_IN_SWIFTPM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Equatable, Part of #174 but I was unable to create a diff between just this PR and the source branch of that PR.