Skip to content

Commit

Permalink
dedupe public key cache population for CHIPToolKeypair
Browse files Browse the repository at this point in the history
  • Loading branch information
kiel-apple committed Nov 4, 2024
1 parent d328eaf commit a76bdff
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions examples/darwin-framework-tool/commands/common/CHIPToolKeypair.mm
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,18 @@ - (SecKeyRef)publicKey
};
_mPublicKey = SecKeyCreateWithData((__bridge CFDataRef) publicKeyNSData, (__bridge CFDictionaryRef) attributes, nullptr);
}
}

- (SecKeyRef)publicKey
{
[self _populatePublicKeyIfNecessary];

return _mPublicKey;
}

- (SecKeyRef)copyPublicKey
{
if (_mPublicKey == nil) {
chip::Crypto::P256PublicKey publicKey = _mKeyPair.Pubkey();
NSData * publicKeyNSData = [NSData dataWithBytes:publicKey.Bytes() length:publicKey.Length()];
NSDictionary * attributes = @{
(__bridge NSString *) kSecAttrKeyClass : (__bridge NSString *) kSecAttrKeyClassPublic,
(NSString *) kSecAttrKeyType : (NSString *) kSecAttrKeyTypeECSECPrimeRandom,
(NSString *) kSecAttrKeySizeInBits : @Public_KeySize,
(NSString *) kSecAttrLabel : kCHIPToolKeychainLabel,
(NSString *) kSecAttrApplicationTag : @CHIPPlugin_CAKeyTag,
};
_mPublicKey = SecKeyCreateWithData((__bridge CFDataRef) publicKeyNSData, (__bridge CFDictionaryRef) attributes, nullptr);
}
[self _populatePublicKeyIfNecessary];

if (_mPublicKey) {
CFRetain(_mPublicKey);
Expand Down

0 comments on commit a76bdff

Please sign in to comment.