Overview
Comment: | iOS: A few code modernizations |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
6205c4feae08c9f1f8c85e8516762a68 |
User & Date: | js 2017-11-26 19:19:07 |
Context
2017-11-26
| ||
20:09 | iOS: Add initial parts of support for key files check-in: 43dbe5c8cb user: js tags: trunk | |
19:19 | iOS: A few code modernizations check-in: 6205c4feae user: js tags: trunk | |
15:01 | Add support for using a keyfile check-in: f13f84c5b9 user: js tags: trunk | |
Changes
Changes to LegacyPasswordGenerator.m.
︙ | ︙ | |||
27 28 29 30 31 32 33 | @synthesize output = _output; + (instancetype)generator { return [[[self alloc] init] autorelease]; } | | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | @synthesize output = _output; + (instancetype)generator { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; _length = 16; return self; } |
︙ | ︙ | |||
55 56 57 58 59 60 61 | - (void)derivePassword { OFSHA256Hash *siteHash = [OFSHA256Hash cryptoHash]; size_t passphraseLength, combinedPassphraseLength; char *combinedPassphrase; | | | | | | | | | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | - (void)derivePassword { OFSHA256Hash *siteHash = [OFSHA256Hash cryptoHash]; size_t passphraseLength, combinedPassphraseLength; char *combinedPassphrase; [siteHash updateWithBuffer: _site.UTF8String length: _site.UTF8StringLength]; if (_output != NULL) { of_explicit_memset(_output, 0, _length); [self freeMemory: _output]; } _output = [self allocMemoryWithSize: _length + 1]; passphraseLength = combinedPassphraseLength = strlen(_passphrase); if (_keyfile != nil) { if (SIZE_MAX - combinedPassphraseLength < _keyfile.count) @throw [OFOutOfRangeException exception]; combinedPassphraseLength += _keyfile.count; } if ((combinedPassphrase = malloc(combinedPassphraseLength)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: combinedPassphraseLength]; @try { memcpy(combinedPassphrase, _passphrase, passphraseLength); if (_keyfile != nil) memcpy(combinedPassphrase + passphraseLength, _keyfile.items, _keyfile.count); of_scrypt(8, 524288, 2, siteHash.digest, [siteHash.class digestSize], combinedPassphrase, combinedPassphraseLength, _output, _length); } @finally { of_explicit_memset(combinedPassphrase, 0, combinedPassphraseLength); free(combinedPassphrase); } |
︙ | ︙ |
Changes to NewPasswordGenerator.m.
︙ | ︙ | |||
27 28 29 30 31 32 33 | @synthesize passphrase = _passphrase, output = _output; + (instancetype)generator { return [[[self alloc] init] autorelease]; } | | | | | | | | | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | @synthesize passphrase = _passphrase, output = _output; + (instancetype)generator { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; _length = 16; return self; } - (void)derivePassword { OFSHA384Hash *siteHash = [OFSHA384Hash cryptoHash]; size_t passphraseLength, combinedPassphraseLength; char *combinedPassphrase; [siteHash updateWithBuffer: _site.UTF8String length: _site.UTF8StringLength]; if (_output != NULL) { of_explicit_memset(_output, 0, _length); [self freeMemory: _output]; } _output = [self allocMemoryWithSize: _length + 1]; passphraseLength = combinedPassphraseLength = strlen(_passphrase); if (_keyfile != nil) { if (SIZE_MAX - combinedPassphraseLength < _keyfile.count) @throw [OFOutOfRangeException exception]; combinedPassphraseLength += _keyfile.count; } if ((combinedPassphrase = malloc(combinedPassphraseLength)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: combinedPassphraseLength]; @try { memcpy(combinedPassphrase, _passphrase, passphraseLength); if (_keyfile != nil) memcpy(combinedPassphrase + passphraseLength, _keyfile.items, _keyfile.count); of_scrypt(8, 524288, 2, siteHash.digest, [siteHash.class digestSize], combinedPassphrase, combinedPassphraseLength, _output, _length); } @finally { of_explicit_memset(combinedPassphrase, 0, combinedPassphraseLength); free(combinedPassphrase); } |
︙ | ︙ |
Changes to ScryptPWGen.m.
︙ | ︙ | |||
101 102 103 104 105 106 107 | optionsParser.lastOption]; [OFApplication terminateWithStatus: 1]; break; } } | | | | | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | optionsParser.lastOption]; [OFApplication terminateWithStatus: 1]; break; } } if (optionsParser.remainingArguments.count != 1) { showHelp(of_stderr, false); [OFApplication terminateWithStatus: 1]; } id <PasswordGenerator> generator = (_legacy ? [LegacyPasswordGenerator generator] : [NewPasswordGenerator generator]); generator.site = optionsParser.remainingArguments.firstObject; if (lengthString != nil) { bool invalid = false; @try { generator.length = (size_t)lengthString.decimalValue; } @catch (OFInvalidFormatException *e) { invalid = true; } @catch (OFOutOfRangeException *e) { invalid = true; } if (invalid) { |
︙ | ︙ | |||
186 187 188 189 190 191 192 | of_explicit_memset(generator.output, 0, generator.length); } } @finally { of_explicit_memset(passphrase, 0, strlen(passphrase)); if (keyfile != nil) | | | 186 187 188 189 190 191 192 193 194 195 196 197 198 | of_explicit_memset(generator.output, 0, generator.length); } } @finally { of_explicit_memset(passphrase, 0, strlen(passphrase)); if (keyfile != nil) of_explicit_memset(keyfile.items, 0, keyfile.count); } [OFApplication terminate]; } @end |
Changes to iOS/AboutController.m.
︙ | ︙ | |||
62 63 64 65 66 67 68 | @implementation AboutController - (void)viewDidLoad { [super viewDidLoad]; self.automaticallyAdjustsScrollViewInsets = NO; | | | | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | @implementation AboutController - (void)viewDidLoad { [super viewDidLoad]; self.automaticallyAdjustsScrollViewInsets = NO; NSDictionary *infoDictionary = NSBundle.mainBundle.infoDictionary; NSString *version = infoDictionary[@"CFBundleShortVersionString"]; NSString *aboutHTML = [aboutHTMLTemplate stringByReplacingOccurrencesOfString: @"{version}" withString: version]; [self.webView loadHTMLString: aboutHTML baseURL: nil]; } - (void)dealloc { [_webView release]; [super dealloc]; } - (BOOL)webView: (UIWebView *)webView shouldStartLoadWithRequest: (NSURLRequest *)request navigationType: (UIWebViewNavigationType)navigationType { if (navigationType == UIWebViewNavigationTypeLinkClicked) { [UIApplication.sharedApplication openURL: request.URL options: @{} completionHandler: ^ (BOOL success) { }]; return NO; } return YES; } @end |
Changes to iOS/AddSiteController.m.
︙ | ︙ | |||
50 51 52 53 54 55 56 | [_mainViewController release]; [super dealloc]; } - (IBAction)done: (id)sender { | | | | | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | [_mainViewController release]; [super dealloc]; } - (IBAction)done: (id)sender { OFString *name = self.nameField.text.OFObject; OFString *lengthString = self.lengthField.text.OFObject; bool lengthValid = true; size_t length; if (name.length == 0) { showAlert(self, @"Name missing", @"Please enter a name."); return; } @try { length = (size_t)lengthString.decimalValue; if (length < 3 || length > 64) lengthValid = false; } @catch (OFInvalidFormatException *e) { lengthValid = false; } |
︙ | ︙ |
Changes to iOS/MainViewController.m.
︙ | ︙ | |||
70 71 72 73 74 75 76 | dequeueReusableCellWithIdentifier: @"site"]; if (cell == nil) cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: @"site"] autorelease]; | | | | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | dequeueReusableCellWithIdentifier: @"site"]; if (cell == nil) cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: @"site"] autorelease]; cell.textLabel.text = self.sites[indexPath.row].NSObject; return cell; } - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { self.sites = [_siteStorage sitesWithFilter: _searchBar.text.OFObject]; [_tableView reloadData]; } - (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath { [self performSegueWithIdentifier: @"showDetails" |
︙ | ︙ |
Changes to iOS/ShowDetailsController.m.
︙ | ︙ | |||
73 74 75 76 77 78 79 | indexPath = self.mainViewController.tableView.indexPathForSelectedRow; [_name release]; _name = [self.mainViewController.sites[indexPath.row] retain]; _length = [siteStorage lengthForSite: _name]; _legacy = [siteStorage isSiteLegacy: _name]; | | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | indexPath = self.mainViewController.tableView.indexPathForSelectedRow; [_name release]; _name = [self.mainViewController.sites[indexPath.row] retain]; _length = [siteStorage lengthForSite: _name]; _legacy = [siteStorage isSiteLegacy: _name]; self.nameField.text = _name.NSObject; self.lengthField.text = [NSString stringWithFormat: @"%zu", _length]; self.legacySwitch.on = _legacy; [self.mainViewController.tableView deselectRowAtIndexPath: indexPath animated: YES]; } |
︙ | ︙ | |||
178 179 180 181 182 183 184 | generator = [LegacyPasswordGenerator generator]; else generator = [NewPasswordGenerator generator]; generator.site = _name; generator.length = _length; | | | 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | generator = [LegacyPasswordGenerator generator]; else generator = [NewPasswordGenerator generator]; generator.site = _name; generator.length = _length; passphrase = of_strdup(self.passphraseField.text.UTF8String); generator.passphrase = passphrase; mainStoryboard = [UIStoryboard storyboardWithName: @"Main" bundle: nil]; activityController = [mainStoryboard instantiateViewControllerWithIdentifier: @"activityIndicator"]; [self.navigationController.view addSubview: activityController.view]; |
︙ | ︙ |
Changes to iOS/scrypt-pwgen.xcodeproj/project.pbxproj.
︙ | ︙ | |||
175 176 177 178 179 180 181 | }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 4B2E52D41DA942840040D091 /* Project object */ = { isa = PBXProject; attributes = { | | | 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 4B2E52D41DA942840040D091 /* Project object */ = { isa = PBXProject; attributes = { LastUpgradeCheck = 0910; ORGANIZATIONNAME = "Jonathan Schleifer"; TargetAttributes = { 4B2E52DB1DA942840040D091 = { CreatedOnToolsVersion = 8.0; DevelopmentTeam = MXKNFCKFL6; ProvisioningStyle = Automatic; }; |
︙ | ︙ | |||
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = dwarf; | > > > > > > | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = dwarf; |
︙ | ︙ | |||
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; SDKROOT = iphoneos; }; name = Debug; }; 4B2E52F21DA942840040D091 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; | > > > > > > > | 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; name = Debug; }; 4B2E52F21DA942840040D091 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_ARC = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; |
︙ | ︙ |