Skip to content

Commit

Permalink
implement copyPublicKey for MTRTestKeys; add TODO note about opti…
Browse files Browse the repository at this point in the history
…onal method calls
  • Loading branch information
kiel-apple committed Oct 31, 2024
1 parent a3ba7d2 commit 32e8525
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/darwin/Framework/CHIPTests/MTRCertificateTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ - (void)testGenerateIntermediateCert

__auto_type * intermediateKeys = [[MTRTestKeys alloc] init];
XCTAssertNotNil(intermediateKeys);
// TODO: there are several places in our tests where we call `copyPublicKey` on objects without first
// seeing if it's implemented by the receiver. (the `MTRKeypair` protocol says both `publicKey` and
// `copyPublicKey` are optional.)
__auto_type * intermediatePublicKey = intermediateKeys.copyPublicKey;
XCTAssert(intermediatePublicKey != NULL);
CFAutorelease(intermediatePublicKey);
Expand Down
7 changes: 7 additions & 0 deletions src/darwin/Framework/CHIPTests/TestHelpers/MTRTestKeys.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ - (NSData *)publicKeyData
return (__bridge_transfer NSData *) SecKeyCopyExternalRepresentation([self publicKey], nil);
}

- (SecKeyRef)copyPublicKey {
// because this varies significantly from the actual implementations,
// it's probably not a great idea to rely on this for memory leak behavior information.
CFRetain(_publicKey);
return _publicKey;
}

- (instancetype)init
{
if (!(self = [super init])) {
Expand Down

0 comments on commit 32e8525

Please sign in to comment.