Skip to content

Commit

Permalink
Fixes padding bug in base64 encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
jensutbult committed Nov 7, 2024
1 parent f64da37 commit a2e92d9
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions YubiKit/YubiKit/Helpers/Additions/YKFNSDataAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,9 @@ - (instancetype)ykf_initWithWebsafeBase64EncodedString:(NSString *)websafeBase64
NSMutableString *base64EncodedString = [[NSMutableString alloc] initWithString:websafeBase64EncodedData];
[base64EncodedString replaceOccurrencesOfString:@"-" withString:@"+" options:0 range:NSMakeRange(0, [base64EncodedString length])];
[base64EncodedString replaceOccurrencesOfString:@"_" withString:@"/" options:0 range:NSMakeRange(0, [base64EncodedString length])];
if ((dataLen % 3) == 1){
[base64EncodedString appendString:@"=="];
}
else if ((dataLen % 3) == 2) {
[base64EncodedString appendString:@"="];
if (dataLen % 4 != 0) {
NSString *padding = [@"" stringByPaddingToLength: 4 - (dataLen % 4) withString:@"=" startingAtIndex:0];
[base64EncodedString appendString:padding];
}
return [self initWithBase64EncodedString:base64EncodedString options:0];
}
Expand Down

0 comments on commit a2e92d9

Please sign in to comment.