From 4c7e653ceff0973f779264ecb179ff0e87902716 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 6 May 2019 13:30:39 +1000 Subject: [PATCH] Hook up public key checking --- .../NewContactThreadViewController.m | 39 ++++++++++++------- .../translations/en.lproj/Localizable.strings | 2 + 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Signal/src/ViewControllers/NewContactThreadViewController.m b/Signal/src/ViewControllers/NewContactThreadViewController.m index 10010a734..a06689d06 100644 --- a/Signal/src/ViewControllers/NewContactThreadViewController.m +++ b/Signal/src/ViewControllers/NewContactThreadViewController.m @@ -398,18 +398,24 @@ NS_ASSUME_NONNULL_BEGIN // Loki: // ======== NSString *publicKey = self.searchBar.text; - - // TODO: Validate public key and show an error if something's wrong - - OWSTableSection *newConversationSection = [OWSTableSection new]; - [newConversationSection - addItem:[OWSTableItem disclosureItemWithText:NSLocalizedString(@"Start a Conversation", @"") - accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, @"start_conversation") - customRowHeight:UITableViewAutomaticDimension - actionBlock:^{ - [weakSelf newConversationWithRecipientId:publicKey]; - }]]; - [contents addSection:newConversationSection]; + BOOL isValid = [ECKeyPair isValidHexEncodedPublicKeyWithCandidate:publicKey]; + if (!isValid) { + OWSTableSection *invalidPublicKeySection = [OWSTableSection new]; + [invalidPublicKeySection + addItem:[OWSTableItem softCenterLabelItemWithText:NSLocalizedString(@"Invalid public key", @"") + customRowHeight:UITableViewAutomaticDimension]]; + [contents addSection:invalidPublicKeySection]; + } else { + OWSTableSection *newConversationSection = [OWSTableSection new]; + [newConversationSection + addItem:[OWSTableItem disclosureItemWithText:NSLocalizedString(@"Start a Conversation", @"") + accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, @"start_conversation") + customRowHeight:UITableViewAutomaticDimension + actionBlock:^{ + [weakSelf newConversationWithRecipientId:publicKey]; + }]]; + [contents addSection:newConversationSection]; + } // ======== for (OWSTableSection *section in [self contactsSectionsForSearch]) { [contents addSection:section]; @@ -728,13 +734,18 @@ NS_ASSUME_NONNULL_BEGIN [sections addObject:inviteeSection]; } + // Loki: + // ======== + NSString *publicKey = self.searchBar.text; + BOOL isValidPublicKey = [ECKeyPair isValidHexEncodedPublicKeyWithCandidate:publicKey]; + // ======== - if (!hasSearchResults) { + if (isValidPublicKey && !hasSearchResults) { // No Search Results OWSTableSection *noResultsSection = [OWSTableSection new]; [noResultsSection addItem:[OWSTableItem softCenterLabelItemWithText: - NSLocalizedString(@"SETTINGS_BLOCK_LIST_NO_SEARCH_RESULTS", + NSLocalizedString(@"No search results", @"A label that indicates the user's search has no matching results.") customRowHeight:UITableViewAutomaticDimension]]; diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index dc3a312f6..d64cbf1bf 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -2566,3 +2566,5 @@ "Your mnemonic couldn't be verified. Please check what you entered and try again." = "Your mnemonic couldn't be verified. Please check what you entered and try again."; "Search by name or public key" = "Search by name or public key"; "Start a Conversation" = "Start a Conversation"; +"Invalid public key" = "Invalid public key"; +"No search results" = "No search results";