Skip to content
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

Enable chaining for select application #160

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,23 @@ -(instancetype)initWithConnectionController:(id<YKFConnectionControllerProtocol>
}

- (void)selectApplication:(YKFSelectApplicationAPDU *)apdu completion:(YKFSmartCardInterfaceResponseBlock)completion {
[self.connectionController execute:apdu completion:^(NSData *response, NSError *error, NSTimeInterval executionTime) {
[self executeCommand:apdu completion:^(NSData * _Nullable data, NSError * _Nullable error) {
if (error) {
completion(nil, error);
return;
}
UInt16 statusCode = [self statusCodeFromKeyResponse:response];
NSData *data = [self dataFromKeyResponse:response];
if (statusCode == YKFAPDUErrorCodeNoError) {
completion(data, nil);
} else if (statusCode == YKFAPDUErrorCodeMissingFile || statusCode == YKFAPDUErrorCodeInsNotSupported) {
NSError *error = [YKFSessionError errorWithCode:YKFSessionErrorMissingApplicationCode];
completion(nil, error);
if ([error isKindOfClass:[YKFSessionError class]]) {
UInt16 statusCode = error.code;
if (statusCode == YKFAPDUErrorCodeMissingFile || statusCode == YKFAPDUErrorCodeInsNotSupported) {
NSError *error = [YKFSessionError errorWithCode:YKFSessionErrorMissingApplicationCode];
completion(nil, error);
} else {
NSAssert(TRUE, @"The key returned an unexpected SW when selecting application");
NSError *error = [YKFSessionError errorWithCode:YKFSessionErrorUnexpectedStatusCode];
completion(nil, error);
}
} else {
completion(nil, error);
}
} else {
NSAssert(TRUE, @"The key returned an unexpected SW when selecting application");
NSError *error = [YKFSessionError errorWithCode:YKFSessionErrorUnexpectedStatusCode];
completion(nil, error);
completion(data, nil);
}
}];
}
Expand Down Expand Up @@ -101,7 +102,7 @@ - (void)executeCommand:(YKFAPDU *)apdu sendRemainingIns:(YKFSmartCardInterfaceSe
ins = 0xA5;
break;
}
YKFAPDU *sendRemainingApdu = [[YKFAPDU alloc] initWithData:[NSData dataWithBytes:(unsigned char[]){0x00, ins, 0x00, 0x00} length:4]];
YKFAPDU *sendRemainingApdu = [[YKFAPDU alloc] initWithData:[NSData dataWithBytes:(unsigned char[]){0x00, ins, 0x00, 0x00, 0x00} length:5]];
// Queue a new request recursively
[self executeCommand:sendRemainingApdu sendRemainingIns:sendRemainingIns timeout:timeout data:data completion:completion];
return;
Expand Down
Loading
Loading