Skip to content

Commit d557f8c

Browse files
committed
Send NSData instead of YKFAPDU as raw command.
1 parent 9dc3c97 commit d557f8c

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

YubiKit/YubiKit/Connections/AccessoryConnection/YKFAccessoryConnection.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,15 @@ - (void)managementSession:(YKFManagementSessionCompletion _Nonnull)callback {
182182
}];
183183
}
184184

185-
- (void)executeRawCommand:(YKFAPDU *)apdu completion:(YKFRawComandCompletion)completion {
185+
- (void)executeRawCommand:(NSData *)data completion:(YKFRawComandCompletion)completion {
186+
YKFAPDU *apdu = [[YKFAPDU alloc] initWithData:data];
186187
[self.connectionController execute:apdu completion:^(NSData * _Nullable data, NSError * _Nullable error, NSTimeInterval executionTime) {
187188
completion(data, error);
188189
}];
189190
}
190191

191-
- (void)executeRawCommand:(YKFAPDU *)apdu timeout:(NSTimeInterval)timeout completion:(YKFRawComandCompletion)completion {
192+
- (void)executeRawCommand:(NSData *)data timeout:(NSTimeInterval)timeout completion:(YKFRawComandCompletion)completion {
193+
YKFAPDU *apdu = [[YKFAPDU alloc] initWithData:data];
192194
[self.connectionController execute:apdu
193195
timeout:timeout
194196
completion:^(NSData * _Nullable response, NSError * _Nullable error, NSTimeInterval executionTime) {

YubiKit/YubiKit/Connections/NFCConnection/YKFNFCConnection.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,15 @@ - (void)managementSession:(YKFManagementSessionCompletion _Nonnull)callback {
138138
}];
139139
}
140140

141-
- (void)executeRawCommand:(YKFAPDU *)apdu completion:(YKFRawComandCompletion)completion {
141+
- (void)executeRawCommand:(NSData *)data completion:(YKFRawComandCompletion)completion {
142+
YKFAPDU *apdu = [[YKFAPDU alloc] initWithData:data];
142143
[self.connectionController execute:apdu completion:^(NSData * _Nullable data, NSError * _Nullable error, NSTimeInterval executionTime) {
143144
completion(data, error);
144145
}];
145146
}
146147

147-
- (void)executeRawCommand:(YKFAPDU *)apdu timeout:(NSTimeInterval)timeout completion:(YKFRawComandCompletion)completion {
148+
- (void)executeRawCommand:(NSData *)data timeout:(NSTimeInterval)timeout completion:(YKFRawComandCompletion)completion {
149+
YKFAPDU *apdu = [[YKFAPDU alloc] initWithData:data];
148150
[self.connectionController execute:apdu
149151
timeout:timeout
150152
completion:^(NSData * _Nullable response, NSError * _Nullable error, NSTimeInterval executionTime) {

YubiKit/YubiKit/Connections/SmartCardConnection/YKFSmartCardConnection.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,15 @@ - (void)u2fSession:(YKFU2FSessionCompletionBlock _Nonnull)completion {
169169
userInfo:@{NSLocalizedDescriptionKey: @"U2F session not supported by YKFSmartCardConnection."}]);
170170
}
171171

172-
- (void)executeRawCommand:(YKFAPDU *)apdu completion:(YKFRawComandCompletion)completion {
172+
- (void)executeRawCommand:(NSData *)data completion:(YKFRawComandCompletion)completion {
173+
YKFAPDU *apdu = [[YKFAPDU alloc] initWithData:data];
173174
[self.connectionController execute:apdu completion:^(NSData * _Nullable data, NSError * _Nullable error, NSTimeInterval executionTime) {
174175
completion(data, error);
175176
}];
176177
}
177178

178-
- (void)executeRawCommand:(YKFAPDU *)apdu timeout:(NSTimeInterval)timeout completion:(YKFRawComandCompletion)completion {
179+
- (void)executeRawCommand:(NSData *)data timeout:(NSTimeInterval)timeout completion:(YKFRawComandCompletion)completion {
180+
YKFAPDU *apdu = [[YKFAPDU alloc] initWithData:data];
179181
[self.connectionController execute:apdu
180182
timeout:timeout
181183
completion:^(NSData * _Nullable response, NSError * _Nullable error, NSTimeInterval executionTime) {

YubiKit/YubiKit/Connections/YKFConnectionProtocol.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ typedef void (^YKFRawComandCompletion)(NSData *_Nullable, NSError *_Nullable);
7373
/// @param completion The unparsed result from the YubiKey or an error.
7474
/// @discussion Use this for communicating with the YubiKey by sending APDUs to the it. Only use this
7575
/// when the `SmartCardInterface` or any of the supplied sessions can not be used.
76-
- (void)executeRawCommand:(YKFAPDU *_Nonnull)apdu completion:(YKFRawComandCompletion _Nonnull)completion;
76+
- (void)executeRawCommand:(NSData *_Nonnull)apdu completion:(YKFRawComandCompletion _Nonnull)completion;
7777

78-
/// @abstract Send a APDU and get the unparsed result as an NSData from the YubiKey.
79-
/// @param apdu The APDU to send to the YubiKey.
78+
/// @abstract Send command as NSData and get the unparsed result as an NSData from the YubiKey.
79+
/// @param data The NSData to send to the YubiKey.
8080
/// @param timeout The timeout to wait before cancelling the command sent to the YubiKey.
8181
/// @param completion The unparsed result from the YubiKey or an error.
8282
/// @discussion Use this for communicating with the YubiKey by sending APDUs to the it. Only use this
8383
/// when the `SmartCardInterface` or any of the supplied sessions can not be used.
84-
- (void)executeRawCommand:(YKFAPDU *_Nonnull)apdu timeout:(NSTimeInterval)timeout completion:(YKFRawComandCompletion _Nonnull)completion;
84+
- (void)executeRawCommand:(NSData *_Nonnull)data timeout:(NSTimeInterval)timeout completion:(YKFRawComandCompletion _Nonnull)completion;
8585

8686
@end
8787

YubiKitTests/Tests/ConnectionTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ class ConnectionTests: XCTestCase {
118118
Thread.sleep(forTimeInterval: 0.5)
119119
firstConnection.connection { connection, error in
120120
// Select Management application
121-
let data = Data([0xA0, 0x00, 0x00, 0x05, 0x27, 0x47, 0x11, 0x17])
122-
let apdu = YKFAPDU(cla: 0x00, ins: 0xa4, p1: 0x04, p2: 0x00, data: data, type: .short)!
123-
connection.executeRawCommand(apdu) { data, error in
121+
let data = Data([0x00, 0xa4, 0x04, 0x00, 0x08, 0xa0, 0x00, 0x00, 0x05, 0x27, 0x47, 0x11, 0x17])
122+
connection.executeRawCommand(data) { data, error in
124123
guard let data else { XCTFail("Failed with error: \(error!)"); return }
124+
print(data.hexDescription)
125125
XCTAssertEqual(data.statusCode, 0x9000)
126126
connectionExpectation.fulfill()
127127
}

0 commit comments

Comments
 (0)