iOS: A few code modernizations
This commit is contained in:
parent
ccc0706caa
commit
f886262722
8 changed files with 46 additions and 33 deletions
|
@ -31,7 +31,7 @@
|
||||||
return [[[self alloc] init] autorelease];
|
return [[[self alloc] init] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
- init
|
- (instancetype)init
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
|
@ -59,8 +59,8 @@
|
||||||
size_t passphraseLength, combinedPassphraseLength;
|
size_t passphraseLength, combinedPassphraseLength;
|
||||||
char *combinedPassphrase;
|
char *combinedPassphrase;
|
||||||
|
|
||||||
[siteHash updateWithBuffer: [_site UTF8String]
|
[siteHash updateWithBuffer: _site.UTF8String
|
||||||
length: [_site UTF8StringLength]];
|
length: _site.UTF8StringLength];
|
||||||
|
|
||||||
if (_output != NULL) {
|
if (_output != NULL) {
|
||||||
of_explicit_memset(_output, 0, _length);
|
of_explicit_memset(_output, 0, _length);
|
||||||
|
@ -71,10 +71,10 @@
|
||||||
|
|
||||||
passphraseLength = combinedPassphraseLength = strlen(_passphrase);
|
passphraseLength = combinedPassphraseLength = strlen(_passphrase);
|
||||||
if (_keyfile != nil) {
|
if (_keyfile != nil) {
|
||||||
if (SIZE_MAX - combinedPassphraseLength < [_keyfile count])
|
if (SIZE_MAX - combinedPassphraseLength < _keyfile.count)
|
||||||
@throw [OFOutOfRangeException exception];
|
@throw [OFOutOfRangeException exception];
|
||||||
|
|
||||||
combinedPassphraseLength += [_keyfile count];
|
combinedPassphraseLength += _keyfile.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((combinedPassphrase = malloc(combinedPassphraseLength)) == NULL)
|
if ((combinedPassphrase = malloc(combinedPassphraseLength)) == NULL)
|
||||||
|
@ -85,10 +85,10 @@
|
||||||
|
|
||||||
if (_keyfile != nil)
|
if (_keyfile != nil)
|
||||||
memcpy(combinedPassphrase + passphraseLength,
|
memcpy(combinedPassphrase + passphraseLength,
|
||||||
[_keyfile items], [_keyfile count]);
|
_keyfile.items, _keyfile.count);
|
||||||
|
|
||||||
of_scrypt(8, 524288, 2, [siteHash digest],
|
of_scrypt(8, 524288, 2, siteHash.digest,
|
||||||
[[siteHash class] digestSize], combinedPassphrase,
|
[siteHash.class digestSize], combinedPassphrase,
|
||||||
combinedPassphraseLength, _output, _length);
|
combinedPassphraseLength, _output, _length);
|
||||||
} @finally {
|
} @finally {
|
||||||
of_explicit_memset(combinedPassphrase, 0,
|
of_explicit_memset(combinedPassphrase, 0,
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
return [[[self alloc] init] autorelease];
|
return [[[self alloc] init] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
- init
|
- (instancetype)init
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@
|
||||||
size_t passphraseLength, combinedPassphraseLength;
|
size_t passphraseLength, combinedPassphraseLength;
|
||||||
char *combinedPassphrase;
|
char *combinedPassphrase;
|
||||||
|
|
||||||
[siteHash updateWithBuffer: [_site UTF8String]
|
[siteHash updateWithBuffer: _site.UTF8String
|
||||||
length: [_site UTF8StringLength]];
|
length: _site.UTF8StringLength];
|
||||||
|
|
||||||
if (_output != NULL) {
|
if (_output != NULL) {
|
||||||
of_explicit_memset(_output, 0, _length);
|
of_explicit_memset(_output, 0, _length);
|
||||||
|
@ -58,10 +58,10 @@
|
||||||
|
|
||||||
passphraseLength = combinedPassphraseLength = strlen(_passphrase);
|
passphraseLength = combinedPassphraseLength = strlen(_passphrase);
|
||||||
if (_keyfile != nil) {
|
if (_keyfile != nil) {
|
||||||
if (SIZE_MAX - combinedPassphraseLength < [_keyfile count])
|
if (SIZE_MAX - combinedPassphraseLength < _keyfile.count)
|
||||||
@throw [OFOutOfRangeException exception];
|
@throw [OFOutOfRangeException exception];
|
||||||
|
|
||||||
combinedPassphraseLength += [_keyfile count];
|
combinedPassphraseLength += _keyfile.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((combinedPassphrase = malloc(combinedPassphraseLength)) == NULL)
|
if ((combinedPassphrase = malloc(combinedPassphraseLength)) == NULL)
|
||||||
|
@ -72,10 +72,10 @@
|
||||||
|
|
||||||
if (_keyfile != nil)
|
if (_keyfile != nil)
|
||||||
memcpy(combinedPassphrase + passphraseLength,
|
memcpy(combinedPassphrase + passphraseLength,
|
||||||
[_keyfile items], [_keyfile count]);
|
_keyfile.items, _keyfile.count);
|
||||||
|
|
||||||
of_scrypt(8, 524288, 2, [siteHash digest],
|
of_scrypt(8, 524288, 2, siteHash.digest,
|
||||||
[[siteHash class] digestSize], combinedPassphrase,
|
[siteHash.class digestSize], combinedPassphrase,
|
||||||
combinedPassphraseLength, _output, _length);
|
combinedPassphraseLength, _output, _length);
|
||||||
} @finally {
|
} @finally {
|
||||||
of_explicit_memset(combinedPassphrase, 0,
|
of_explicit_memset(combinedPassphrase, 0,
|
||||||
|
|
|
@ -105,7 +105,7 @@ showHelp(OFStream *output, bool verbose)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([[optionsParser remainingArguments] count] != 1) {
|
if (optionsParser.remainingArguments.count != 1) {
|
||||||
showHelp(of_stderr, false);
|
showHelp(of_stderr, false);
|
||||||
|
|
||||||
[OFApplication terminateWithStatus: 1];
|
[OFApplication terminateWithStatus: 1];
|
||||||
|
@ -114,13 +114,13 @@ showHelp(OFStream *output, bool verbose)
|
||||||
id <PasswordGenerator> generator = (_legacy
|
id <PasswordGenerator> generator = (_legacy
|
||||||
? [LegacyPasswordGenerator generator]
|
? [LegacyPasswordGenerator generator]
|
||||||
: [NewPasswordGenerator generator]);
|
: [NewPasswordGenerator generator]);
|
||||||
generator.site = [[optionsParser remainingArguments] firstObject];
|
generator.site = optionsParser.remainingArguments.firstObject;
|
||||||
|
|
||||||
if (lengthString != nil) {
|
if (lengthString != nil) {
|
||||||
bool invalid = false;
|
bool invalid = false;
|
||||||
|
|
||||||
@try {
|
@try {
|
||||||
generator.length = (size_t)[lengthString decimalValue];
|
generator.length = (size_t)lengthString.decimalValue;
|
||||||
} @catch (OFInvalidFormatException *e) {
|
} @catch (OFInvalidFormatException *e) {
|
||||||
invalid = true;
|
invalid = true;
|
||||||
} @catch (OFOutOfRangeException *e) {
|
} @catch (OFOutOfRangeException *e) {
|
||||||
|
@ -190,7 +190,7 @@ showHelp(OFStream *output, bool verbose)
|
||||||
of_explicit_memset(passphrase, 0, strlen(passphrase));
|
of_explicit_memset(passphrase, 0, strlen(passphrase));
|
||||||
|
|
||||||
if (keyfile != nil)
|
if (keyfile != nil)
|
||||||
of_explicit_memset([keyfile items], 0, [keyfile count]);
|
of_explicit_memset(keyfile.items, 0, keyfile.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
[OFApplication terminate];
|
[OFApplication terminate];
|
||||||
|
|
|
@ -66,7 +66,7 @@ static NSString *aboutHTMLTemplate =
|
||||||
|
|
||||||
self.automaticallyAdjustsScrollViewInsets = NO;
|
self.automaticallyAdjustsScrollViewInsets = NO;
|
||||||
|
|
||||||
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
|
NSDictionary *infoDictionary = NSBundle.mainBundle.infoDictionary;
|
||||||
NSString *version = infoDictionary[@"CFBundleShortVersionString"];
|
NSString *version = infoDictionary[@"CFBundleShortVersionString"];
|
||||||
NSString *aboutHTML = [aboutHTMLTemplate
|
NSString *aboutHTML = [aboutHTMLTemplate
|
||||||
stringByReplacingOccurrencesOfString: @"{version}"
|
stringByReplacingOccurrencesOfString: @"{version}"
|
||||||
|
@ -87,7 +87,7 @@ static NSString *aboutHTMLTemplate =
|
||||||
navigationType: (UIWebViewNavigationType)navigationType
|
navigationType: (UIWebViewNavigationType)navigationType
|
||||||
{
|
{
|
||||||
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
|
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
|
||||||
[[UIApplication sharedApplication] openURL: request.URL
|
[UIApplication.sharedApplication openURL: request.URL
|
||||||
options: @{}
|
options: @{}
|
||||||
completionHandler: ^ (BOOL success) {
|
completionHandler: ^ (BOOL success) {
|
||||||
}];
|
}];
|
||||||
|
|
|
@ -54,18 +54,18 @@ showAlert(UIViewController *controller, NSString *title, NSString *message)
|
||||||
|
|
||||||
- (IBAction)done: (id)sender
|
- (IBAction)done: (id)sender
|
||||||
{
|
{
|
||||||
OFString *name = [self.nameField.text OFObject];
|
OFString *name = self.nameField.text.OFObject;
|
||||||
OFString *lengthStr = [self.lengthField.text OFObject];
|
OFString *lengthString = self.lengthField.text.OFObject;
|
||||||
bool lengthValid = true;
|
bool lengthValid = true;
|
||||||
size_t length;
|
size_t length;
|
||||||
|
|
||||||
if ([name length] == 0) {
|
if (name.length == 0) {
|
||||||
showAlert(self, @"Name missing", @"Please enter a name.");
|
showAlert(self, @"Name missing", @"Please enter a name.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@try {
|
@try {
|
||||||
length = (size_t)[lengthStr decimalValue];
|
length = (size_t)lengthString.decimalValue;
|
||||||
|
|
||||||
if (length < 3 || length > 64)
|
if (length < 3 || length > 64)
|
||||||
lengthValid = false;
|
lengthValid = false;
|
||||||
|
|
|
@ -74,7 +74,7 @@
|
||||||
initWithStyle: UITableViewCellStyleDefault
|
initWithStyle: UITableViewCellStyleDefault
|
||||||
reuseIdentifier: @"site"] autorelease];
|
reuseIdentifier: @"site"] autorelease];
|
||||||
|
|
||||||
cell.textLabel.text = [self.sites[indexPath.row] NSObject];
|
cell.textLabel.text = self.sites[indexPath.row].NSObject;
|
||||||
|
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@
|
||||||
- (void)searchBar:(UISearchBar *)searchBar
|
- (void)searchBar:(UISearchBar *)searchBar
|
||||||
textDidChange:(NSString *)searchText
|
textDidChange:(NSString *)searchText
|
||||||
{
|
{
|
||||||
self.sites = [_siteStorage sitesWithFilter: [_searchBar.text OFObject]];
|
self.sites = [_siteStorage sitesWithFilter: _searchBar.text.OFObject];
|
||||||
[_tableView reloadData];
|
[_tableView reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ clearNSMutableString(NSMutableString *string)
|
||||||
_length = [siteStorage lengthForSite: _name];
|
_length = [siteStorage lengthForSite: _name];
|
||||||
_legacy = [siteStorage isSiteLegacy: _name];
|
_legacy = [siteStorage isSiteLegacy: _name];
|
||||||
|
|
||||||
self.nameField.text = [_name NSObject];
|
self.nameField.text = _name.NSObject;
|
||||||
self.lengthField.text = [NSString stringWithFormat: @"%zu", _length];
|
self.lengthField.text = [NSString stringWithFormat: @"%zu", _length];
|
||||||
self.legacySwitch.on = _legacy;
|
self.legacySwitch.on = _legacy;
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ clearNSMutableString(NSMutableString *string)
|
||||||
generator.site = _name;
|
generator.site = _name;
|
||||||
generator.length = _length;
|
generator.length = _length;
|
||||||
|
|
||||||
passphrase = of_strdup([self.passphraseField.text UTF8String]);
|
passphrase = of_strdup(self.passphraseField.text.UTF8String);
|
||||||
generator.passphrase = passphrase;
|
generator.passphrase = passphrase;
|
||||||
|
|
||||||
mainStoryboard = [UIStoryboard storyboardWithName: @"Main"
|
mainStoryboard = [UIStoryboard storyboardWithName: @"Main"
|
||||||
|
|
|
@ -179,7 +179,7 @@
|
||||||
4B2E52D41DA942840040D091 /* Project object */ = {
|
4B2E52D41DA942840040D091 /* Project object */ = {
|
||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
attributes = {
|
attributes = {
|
||||||
LastUpgradeCheck = 0820;
|
LastUpgradeCheck = 0910;
|
||||||
ORGANIZATIONNAME = "Jonathan Schleifer";
|
ORGANIZATIONNAME = "Jonathan Schleifer";
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
4B2E52DB1DA942840040D091 = {
|
4B2E52DB1DA942840040D091 = {
|
||||||
|
@ -267,7 +267,9 @@
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||||
CLANG_CXX_LIBRARY = "libc++";
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
|
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_COMMA = YES;
|
||||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||||
|
@ -275,7 +277,11 @@
|
||||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||||
CLANG_WARN_INT_CONVERSION = 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_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
|
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||||
|
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||||
CLANG_WARN_SUSPICIOUS_MOVES = YES;
|
CLANG_WARN_SUSPICIOUS_MOVES = YES;
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||||
|
@ -301,6 +307,7 @@
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||||
MTL_ENABLE_DEBUG_INFO = YES;
|
MTL_ENABLE_DEBUG_INFO = YES;
|
||||||
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
};
|
};
|
||||||
name = Debug;
|
name = Debug;
|
||||||
|
@ -313,7 +320,9 @@
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||||
CLANG_CXX_LIBRARY = "libc++";
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
|
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_COMMA = YES;
|
||||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||||
|
@ -321,7 +330,11 @@
|
||||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||||
CLANG_WARN_INT_CONVERSION = 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_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
|
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||||
|
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||||
CLANG_WARN_SUSPICIOUS_MOVES = YES;
|
CLANG_WARN_SUSPICIOUS_MOVES = YES;
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue