Skip to content

Commit

Permalink
Adding syntactic sugar to make MTRNOCChainIssuer work better with Swi…
Browse files Browse the repository at this point in the history
…ft apps
  • Loading branch information
sharadb-amazon committed Aug 25, 2022
1 parent 5c2334a commit c64e328
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/MTRNOCChainIssuer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)onNOCChainGenerationNeeded:(CSRInfo *)csrInfo
attestationInfo:(AttestationInfo *)attestationInfo
onNOCChainGenerationComplete:(void (^)(NSData * operationalCertificate, NSData * intermediateCertificate,
NSData * rootCertificate, NSData * ipk, NSNumber * adminSubject,
onNOCChainGenerationComplete:(BOOL (^)(NSData * operationalCertificate, NSData * intermediateCertificate,
NSData * rootCertificate, NSData * _Nullable ipk, NSNumber * _Nullable adminSubject,
NSError * __autoreleasing * error))onNOCChainGenerationComplete;

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class MTROperationalCredentialsDelegate : public chip::Controller::OperationalCr
* If ipk and adminSubject are non nil, then they will be used in the AddNOC command sent to the commissionee. If they are not
* populated, then the values provided in the MTRDeviceController initialization will be used.
*/
void onNOCChainGenerationComplete(NSData * operationalCertificate, NSData * intermediateCertificate, NSData * rootCertificate,
BOOL onNOCChainGenerationComplete(NSData * operationalCertificate, NSData * intermediateCertificate, NSData * rootCertificate,
NSData * _Nullable ipk, NSNumber * _Nullable adminSubject, NSError * __autoreleasing * error);

void setNSError(CHIP_ERROR err, NSError * __autoreleasing * outError);
Expand Down
14 changes: 8 additions & 6 deletions src/darwin/Framework/CHIP/MTROperationalCredentialsDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@
dispatch_sync(mNocChainIssuerQueue, ^{
[mNocChainIssuer onNOCChainGenerationNeeded:csrInfo
attestationInfo:attestationInfo
onNOCChainGenerationComplete:^void(NSData * operationalCertificate, NSData * intermediateCertificate,
onNOCChainGenerationComplete:^BOOL(NSData * operationalCertificate, NSData * intermediateCertificate,
NSData * rootCertificate, NSData * ipk, NSNumber * adminSubject, NSError * __autoreleasing * error) {
onNOCChainGenerationComplete(
return onNOCChainGenerationComplete(
operationalCertificate, intermediateCertificate, rootCertificate, ipk, adminSubject, error);
}];
});
Expand All @@ -222,13 +222,13 @@
}
}

void MTROperationalCredentialsDelegate::onNOCChainGenerationComplete(NSData * operationalCertificate,
BOOL MTROperationalCredentialsDelegate::onNOCChainGenerationComplete(NSData * operationalCertificate,
NSData * intermediateCertificate, NSData * rootCertificate, NSData * _Nullable ipk, NSNumber * _Nullable adminSubject,
NSError * __autoreleasing * error)
{
if (operationalCertificate == nil || intermediateCertificate == nil || rootCertificate == nil) {
setNSError(CHIP_ERROR_INVALID_ARGUMENT, error);
return;
return NO;
}

// use ipk and adminSubject from CommissioningParameters if not passed in.
Expand All @@ -240,7 +240,7 @@
});
if (!commissioningParameters.HasValue()) {
setNSError(CHIP_ERROR_INCORRECT_STATE, error);
return;
return NO;
}

chip::Optional<chip::Crypto::AesCcm128KeySpan> ipkOptional;
Expand All @@ -249,7 +249,7 @@
if (ipk != nil) {
if ([ipk length] != sizeof(ipkValue)) {
setNSError(CHIP_ERROR_INCORRECT_STATE, error);
return;
return NO;
}
memcpy(&ipkValue[0], [ipk bytes], [ipk length]);
ipkOptional.SetValue(ipkTempSpan);
Expand All @@ -273,7 +273,9 @@
if (err != CHIP_NO_ERROR) {
MTR_LOG_ERROR("Failed to SetNocChain for the device: %" CHIP_ERROR_FORMAT, err.Format());
setNSError(CHIP_ERROR_INCORRECT_STATE, error);
return NO;
}
return YES;
}

CHIP_ERROR MTROperationalCredentialsDelegate::LocalGenerateNOCChain(const chip::ByteSpan & csrElements,
Expand Down

0 comments on commit c64e328

Please sign in to comment.