Clean up DecryptedProfile
This commit is contained in:
parent
da5a0a7f96
commit
6c1c4b931d
@ -169,7 +169,6 @@
|
||||
341D392925472F3B00996E7B /* CVViewState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 341D392825472F3B00996E7B /* CVViewState.swift */; };
|
||||
3420CF6D26327B1A00E7DCB0 /* CVBackgroundContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3420CF6C26327B1A00E7DCB0 /* CVBackgroundContainer.swift */; };
|
||||
3420CF6F2638A01A00E7DCB0 /* CVWallpaperBlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3420CF6E2638A01A00E7DCB0 /* CVWallpaperBlurView.swift */; };
|
||||
3421981C21061D2E00C57195 /* ByteParserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3421981B21061D2E00C57195 /* ByteParserTest.swift */; };
|
||||
34235F3824213550008C74CB /* ConversationSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34235F3724213550008C74CB /* ConversationSettingsViewController.swift */; };
|
||||
3426A366255C854B0036407F /* CVItemViewModelImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3426A365255C854A0036407F /* CVItemViewModelImpl.swift */; };
|
||||
3426A368255D7BCA0036407F /* ConversationViewController+MessageActionsDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3426A367255D7BCA0036407F /* ConversationViewController+MessageActionsDelegate.swift */; };
|
||||
@ -2282,7 +2281,6 @@
|
||||
F9C5CDDE289453B400548EEE /* OWS2FAManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F9C5CB0C289453B200548EEE /* OWS2FAManager.m */; settings = {COMPILER_FLAGS = "-fcxx-modules"; }; };
|
||||
F9C5CDDF289453B400548EEE /* ImageQuality.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9C5CB0D289453B200548EEE /* ImageQuality.swift */; settings = {COMPILER_FLAGS = "-fcxx-modules"; }; };
|
||||
F9C5CDE0289453B400548EEE /* DarwinNotificationCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = F9C5CB0E289453B200548EEE /* DarwinNotificationCenter.m */; settings = {COMPILER_FLAGS = "-fcxx-modules"; }; };
|
||||
F9C5CDE1289453B400548EEE /* ByteParser.m in Sources */ = {isa = PBXBuildFile; fileRef = F9C5CB0F289453B200548EEE /* ByteParser.m */; settings = {COMPILER_FLAGS = "-fcxx-modules"; }; };
|
||||
F9C5CDE2289453B400548EEE /* ThreadBacked.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9C5CB10289453B200548EEE /* ThreadBacked.swift */; settings = {COMPILER_FLAGS = "-fcxx-modules"; }; };
|
||||
F9C5CDE3289453B400548EEE /* MailtoLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9C5CB11289453B200548EEE /* MailtoLink.swift */; settings = {COMPILER_FLAGS = "-fcxx-modules"; }; };
|
||||
F9C5CDE4289453B400548EEE /* StorageService.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9C5CB12289453B200548EEE /* StorageService.swift */; settings = {COMPILER_FLAGS = "-fcxx-modules"; }; };
|
||||
@ -2341,7 +2339,6 @@
|
||||
F9C5CE25289453B400548EEE /* AppReadiness.h in Headers */ = {isa = PBXBuildFile; fileRef = F9C5CB53289453B200548EEE /* AppReadiness.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
F9C5CE26289453B400548EEE /* UserProfileFinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9C5CB54289453B200548EEE /* UserProfileFinder.swift */; settings = {COMPILER_FLAGS = "-fcxx-modules"; }; };
|
||||
F9C5CE27289453B400548EEE /* DarwinNotificationCenter.h in Headers */ = {isa = PBXBuildFile; fileRef = F9C5CB55289453B200548EEE /* DarwinNotificationCenter.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
F9C5CE28289453B400548EEE /* ByteParser.h in Headers */ = {isa = PBXBuildFile; fileRef = F9C5CB56289453B200548EEE /* ByteParser.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
F9C5CE29289453B400548EEE /* ModelReadCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9C5CB57289453B200548EEE /* ModelReadCache.swift */; settings = {COMPILER_FLAGS = "-fcxx-modules"; }; };
|
||||
F9C5CE2A289453B400548EEE /* Platform.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9C5CB58289453B200548EEE /* Platform.swift */; settings = {COMPILER_FLAGS = "-fcxx-modules"; }; };
|
||||
F9C5CE2B289453B400548EEE /* FeatureFlags.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9C5CB59289453B200548EEE /* FeatureFlags.swift */; settings = {COMPILER_FLAGS = "-fcxx-modules"; }; };
|
||||
@ -2696,7 +2693,6 @@
|
||||
341D392825472F3B00996E7B /* CVViewState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVViewState.swift; sourceTree = "<group>"; };
|
||||
3420CF6C26327B1A00E7DCB0 /* CVBackgroundContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVBackgroundContainer.swift; sourceTree = "<group>"; };
|
||||
3420CF6E2638A01A00E7DCB0 /* CVWallpaperBlurView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVWallpaperBlurView.swift; sourceTree = "<group>"; };
|
||||
3421981B21061D2E00C57195 /* ByteParserTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ByteParserTest.swift; sourceTree = "<group>"; };
|
||||
34235F3724213550008C74CB /* ConversationSettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConversationSettingsViewController.swift; sourceTree = "<group>"; };
|
||||
3426A365255C854A0036407F /* CVItemViewModelImpl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVItemViewModelImpl.swift; sourceTree = "<group>"; };
|
||||
3426A367255D7BCA0036407F /* ConversationViewController+MessageActionsDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConversationViewController+MessageActionsDelegate.swift"; sourceTree = "<group>"; };
|
||||
@ -5033,7 +5029,6 @@
|
||||
F9C5CB0C289453B200548EEE /* OWS2FAManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWS2FAManager.m; sourceTree = "<group>"; };
|
||||
F9C5CB0D289453B200548EEE /* ImageQuality.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageQuality.swift; sourceTree = "<group>"; };
|
||||
F9C5CB0E289453B200548EEE /* DarwinNotificationCenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DarwinNotificationCenter.m; sourceTree = "<group>"; };
|
||||
F9C5CB0F289453B200548EEE /* ByteParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ByteParser.m; sourceTree = "<group>"; };
|
||||
F9C5CB10289453B200548EEE /* ThreadBacked.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThreadBacked.swift; sourceTree = "<group>"; };
|
||||
F9C5CB11289453B200548EEE /* MailtoLink.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MailtoLink.swift; sourceTree = "<group>"; };
|
||||
F9C5CB12289453B200548EEE /* StorageService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StorageService.swift; sourceTree = "<group>"; };
|
||||
@ -5092,7 +5087,6 @@
|
||||
F9C5CB53289453B200548EEE /* AppReadiness.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppReadiness.h; sourceTree = "<group>"; };
|
||||
F9C5CB54289453B200548EEE /* UserProfileFinder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserProfileFinder.swift; sourceTree = "<group>"; };
|
||||
F9C5CB55289453B200548EEE /* DarwinNotificationCenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DarwinNotificationCenter.h; sourceTree = "<group>"; };
|
||||
F9C5CB56289453B200548EEE /* ByteParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ByteParser.h; sourceTree = "<group>"; };
|
||||
F9C5CB57289453B200548EEE /* ModelReadCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModelReadCache.swift; sourceTree = "<group>"; };
|
||||
F9C5CB58289453B200548EEE /* Platform.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Platform.swift; sourceTree = "<group>"; };
|
||||
F9C5CB59289453B200548EEE /* FeatureFlags.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeatureFlags.swift; sourceTree = "<group>"; };
|
||||
@ -8244,7 +8238,6 @@
|
||||
6675F65029261E0C007A311E /* APNSRotationStoreTest.swift */,
|
||||
F9B3A92E293554090071EB95 /* ASWebAuthenticationSessionUtilTest.swift */,
|
||||
34F1072126D045290053EF4D /* BatchUpdateTest.swift */,
|
||||
3421981B21061D2E00C57195 /* ByteParserTest.swift */,
|
||||
4C9D347923679C13006A4307 /* ContactStreamTest.swift */,
|
||||
3494BBDF26E66FC30079B11B /* DateUtilTest.swift */,
|
||||
45E7A6A61E71CA7E00D44FB5 /* DisplayableTextFilterTest.swift */,
|
||||
@ -10207,8 +10200,6 @@
|
||||
F9C5CB40289453B200548EEE /* Bench.swift */,
|
||||
668FE09A28B923A4008B9071 /* Bool+SSK.swift */,
|
||||
E7D7C93E28B580AC003F043B /* Bundle+OWS.swift */,
|
||||
F9C5CB56289453B200548EEE /* ByteParser.h */,
|
||||
F9C5CB0F289453B200548EEE /* ByteParser.m */,
|
||||
76387BEF28F4ED73002C7BA5 /* CaseIterable.swift */,
|
||||
661396AC28BE74DC00E0C4DF /* ChainedPromise.swift */,
|
||||
F9C5CB2A289453B200548EEE /* Collection+OWS.swift */,
|
||||
@ -10476,7 +10467,6 @@
|
||||
F9C5CE25289453B400548EEE /* AppReadiness.h in Headers */,
|
||||
F9C5CD39289453B300548EEE /* AxolotlExceptions.h in Headers */,
|
||||
F9C5CD77289453B300548EEE /* BaseModel.h in Headers */,
|
||||
F9C5CE28289453B400548EEE /* ByteParser.h in Headers */,
|
||||
F9C5CD3A289453B300548EEE /* CallKitIdStore.h in Headers */,
|
||||
F9C5CCC9289453B300548EEE /* Contact.h in Headers */,
|
||||
F9C5CCEC289453B300548EEE /* ContactsManagerProtocol.h in Headers */,
|
||||
@ -12669,7 +12659,6 @@
|
||||
D99ABC742A3D0BE10034CD3B /* BitmapsImageParsingTest.swift in Sources */,
|
||||
D9317FD32A4BAC8300075A92 /* BitmapsImagePixelMergingTest.swift in Sources */,
|
||||
D9317FD82A4BC4FC00075A92 /* BitmapsRectTest.swift in Sources */,
|
||||
3421981C21061D2E00C57195 /* ByteParserTest.swift in Sources */,
|
||||
D93108152B34B6BE006A034E /* CallRecordLoaderTest.swift in Sources */,
|
||||
F9C612B4284E466B00B2199A /* CGPointExtensionsTest.swift in Sources */,
|
||||
954AEE6A1DF33E01002E5410 /* ContactsPickerTest.swift in Sources */,
|
||||
@ -12772,7 +12761,6 @@
|
||||
D9AE0ACB29162C160063488B /* BroadcastMediaMessageJobRecord.swift in Sources */,
|
||||
F9C5CE39289453B400548EEE /* BulkProfileFetch.swift in Sources */,
|
||||
E7D7C93F28B580AC003F043B /* Bundle+OWS.swift in Sources */,
|
||||
F9C5CDE1289453B400548EEE /* ByteParser.m in Sources */,
|
||||
F9C5CD32289453B300548EEE /* CallKitIdStore.m in Sources */,
|
||||
D99A2A852AAB9AB9003388D1 /* CallRecord.swift in Sources */,
|
||||
D979CC272AD3933B006AAC49 /* CallRecordIncomingSyncMessageManager.swift in Sources */,
|
||||
|
||||
@ -1,214 +0,0 @@
|
||||
//
|
||||
// Copyright 2018 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import Signal
|
||||
@testable import SignalServiceKit
|
||||
|
||||
class ByteParserTest: XCTestCase {
|
||||
func testGetShort_Empty() {
|
||||
let parser = ByteParser(data: Data(), littleEndian: true)
|
||||
XCTAssertNotNil(parser)
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(0, parser.nextUInt16())
|
||||
XCTAssertTrue(parser.hasError)
|
||||
}
|
||||
|
||||
func testGetShort_littleEndian() {
|
||||
let data = Data([0x01, 0x00, 0x00, 0x01, 0x01, 0x01])
|
||||
let parser = ByteParser(data: data, littleEndian: true)
|
||||
XCTAssertNotNil(parser)
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(1, parser.nextUInt16())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(256, parser.nextUInt16())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(257, parser.nextUInt16())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(0, parser.nextUInt16())
|
||||
XCTAssertTrue(parser.hasError)
|
||||
}
|
||||
|
||||
func testGetShort_bigEndian() {
|
||||
let data = Data([0x01, 0x00, 0x00, 0x01, 0x01, 0x01])
|
||||
let parser = ByteParser(data: data, littleEndian: false)
|
||||
XCTAssertNotNil(parser)
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(256, parser.nextUInt16())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(1, parser.nextUInt16())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(257, parser.nextUInt16())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(0, parser.nextUInt16())
|
||||
XCTAssertTrue(parser.hasError)
|
||||
}
|
||||
|
||||
func testGetInt_Empty() {
|
||||
let parser = ByteParser(data: Data(), littleEndian: true)
|
||||
XCTAssertNotNil(parser)
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(0, parser.nextUInt32())
|
||||
XCTAssertTrue(parser.hasError)
|
||||
}
|
||||
|
||||
func testGetInt_littleEndian() {
|
||||
let data = Data([0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00])
|
||||
let parser = ByteParser(data: data, littleEndian: true)
|
||||
XCTAssertNotNil(parser)
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(1, parser.nextUInt32())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(256, parser.nextUInt32())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(257, parser.nextUInt32())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(0, parser.nextUInt32())
|
||||
XCTAssertTrue(parser.hasError)
|
||||
}
|
||||
|
||||
func testGetInt_bigEndian() {
|
||||
let data = Data([0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01])
|
||||
let parser = ByteParser(data: data, littleEndian: false)
|
||||
XCTAssertNotNil(parser)
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(1, parser.nextUInt32())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(256, parser.nextUInt32())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(257, parser.nextUInt32())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(0, parser.nextUInt32())
|
||||
XCTAssertTrue(parser.hasError)
|
||||
}
|
||||
|
||||
func testGetLong_Empty() {
|
||||
let parser = ByteParser(data: Data(), littleEndian: true)
|
||||
XCTAssertNotNil(parser)
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(0, parser.nextUInt64())
|
||||
XCTAssertTrue(parser.hasError)
|
||||
}
|
||||
|
||||
func testGetLong_littleEndian() {
|
||||
let data = Data([0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
|
||||
let parser = ByteParser(data: data, littleEndian: true)
|
||||
XCTAssertNotNil(parser)
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(1, parser.nextUInt64())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(256, parser.nextUInt64())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(257, parser.nextUInt64())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(0, parser.nextUInt64())
|
||||
XCTAssertTrue(parser.hasError)
|
||||
}
|
||||
|
||||
func testGetLong_bigEndian() {
|
||||
let data = Data([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01])
|
||||
let parser = ByteParser(data: data, littleEndian: false)
|
||||
XCTAssertNotNil(parser)
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(1, parser.nextUInt64())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(256, parser.nextUInt64())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(257, parser.nextUInt64())
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(0, parser.nextUInt64())
|
||||
XCTAssertTrue(parser.hasError)
|
||||
}
|
||||
|
||||
func testReadZero_Empty() {
|
||||
let parser = ByteParser(data: Data(), littleEndian: true)
|
||||
XCTAssertNotNil(parser)
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertFalse(parser.readZero(1))
|
||||
XCTAssertTrue(parser.hasError)
|
||||
}
|
||||
|
||||
func testReadZero() {
|
||||
let data = Data([0x00, 0x01, 0x00, 0x00, 0x01, 0x00])
|
||||
let parser = ByteParser(data: data, littleEndian: true)
|
||||
XCTAssertNotNil(parser)
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertTrue(parser.readZero(1))
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertFalse(parser.readZero(1))
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertTrue(parser.readZero(2))
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertFalse(parser.readZero(2))
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertFalse(parser.readZero(1))
|
||||
XCTAssertTrue(parser.hasError)
|
||||
}
|
||||
|
||||
func testReadBytes_Empty() {
|
||||
let parser = ByteParser(data: Data(), littleEndian: true)
|
||||
XCTAssertNotNil(parser)
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertNil(parser.readBytes(1))
|
||||
XCTAssertTrue(parser.hasError)
|
||||
}
|
||||
|
||||
func testReadBytes() {
|
||||
let data = Data([0x00, 0x01, 0x02, 0x03, 0x04, 0x05])
|
||||
let parser = ByteParser(data: data, littleEndian: true)
|
||||
XCTAssertNotNil(parser)
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(Data([0x00]), parser.readBytes(1))
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(Data([0x01]), parser.readBytes(1))
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(Data([0x02, 0x03]), parser.readBytes(2))
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertEqual(Data([0x04, 0x05]), parser.readBytes(2))
|
||||
XCTAssertFalse(parser.hasError)
|
||||
|
||||
XCTAssertNil(parser.readBytes(1))
|
||||
XCTAssertTrue(parser.hasError)
|
||||
}
|
||||
}
|
||||
@ -150,10 +150,7 @@ public class VersionedProfilesImpl: NSObject, VersionedProfilesSwift, VersionedP
|
||||
return nil
|
||||
}
|
||||
var result = Data()
|
||||
var littleEndian: UInt32 = CFSwapInt32HostToLittle(UInt32(addressProtoData.count))
|
||||
withUnsafePointer(to: &littleEndian) { pointer in
|
||||
result.append(UnsafeBufferPointer(start: pointer, count: 1))
|
||||
}
|
||||
result.append(UInt32(addressProtoData.count).littleEndianData)
|
||||
result.append(addressProtoData)
|
||||
return result
|
||||
}()
|
||||
|
||||
@ -15,7 +15,6 @@ FOUNDATION_EXPORT const unsigned char SignalServiceKitVersionString[];
|
||||
#import <SignalServiceKit/AppReadiness.h>
|
||||
#import <SignalServiceKit/AxolotlExceptions.h>
|
||||
#import <SignalServiceKit/BaseModel.h>
|
||||
#import <SignalServiceKit/ByteParser.h>
|
||||
#import <SignalServiceKit/CallKitIdStore.h>
|
||||
#import <SignalServiceKit/Contact.h>
|
||||
#import <SignalServiceKit/ContactsManagerProtocol.h>
|
||||
|
||||
@ -1,40 +0,0 @@
|
||||
//
|
||||
// Copyright 2018 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
//
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface ByteParser : NSObject
|
||||
|
||||
@property (nonatomic, readonly) BOOL hasError;
|
||||
|
||||
+ (instancetype)new NS_UNAVAILABLE;
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
- (instancetype)initWithData:(NSData *)data littleEndian:(BOOL)littleEndian;
|
||||
|
||||
#pragma mark - UInt16
|
||||
|
||||
- (uint16_t)uint16AtIndex:(NSUInteger)index;
|
||||
- (uint16_t)nextUInt16;
|
||||
|
||||
#pragma mark - UInt32
|
||||
|
||||
- (uint32_t)uint32AtIndex:(NSUInteger)index;
|
||||
- (uint32_t)nextUInt32;
|
||||
|
||||
#pragma mark - UInt64
|
||||
|
||||
- (uint64_t)uint64AtIndex:(NSUInteger)index;
|
||||
- (uint64_t)nextUInt64;
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (BOOL)readZero:(NSUInteger)length;
|
||||
|
||||
- (nullable NSData *)readBytes:(NSUInteger)length;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -1,143 +0,0 @@
|
||||
//
|
||||
// Copyright 2018 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
//
|
||||
|
||||
#import "ByteParser.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface ByteParser ()
|
||||
|
||||
@property (nonatomic, readonly) BOOL littleEndian;
|
||||
@property (nonatomic, readonly) NSData *data;
|
||||
@property (nonatomic) NSUInteger cursor;
|
||||
@property (nonatomic) BOOL hasError;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation ByteParser
|
||||
|
||||
- (instancetype)initWithData:(NSData *)data littleEndian:(BOOL)littleEndian
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_littleEndian = littleEndian;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - UInt16
|
||||
|
||||
- (uint16_t)uint16AtIndex:(NSUInteger)index
|
||||
{
|
||||
uint16_t value;
|
||||
const size_t valueSize = sizeof(value);
|
||||
OWSAssertDebug(valueSize == 2);
|
||||
if (index + valueSize > self.data.length) {
|
||||
self.hasError = YES;
|
||||
return 0;
|
||||
}
|
||||
[self.data getBytes:&value range:NSMakeRange(index, valueSize)];
|
||||
if (self.littleEndian) {
|
||||
return CFSwapInt16LittleToHost(value);
|
||||
} else {
|
||||
return CFSwapInt16BigToHost(value);
|
||||
}
|
||||
}
|
||||
|
||||
- (uint16_t)nextUInt16
|
||||
{
|
||||
uint16_t value = [self uint16AtIndex:self.cursor];
|
||||
self.cursor += sizeof(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
#pragma mark - UInt32
|
||||
|
||||
- (uint32_t)uint32AtIndex:(NSUInteger)index
|
||||
{
|
||||
uint32_t value;
|
||||
const size_t valueSize = sizeof(value);
|
||||
OWSAssertDebug(valueSize == 4);
|
||||
if (index + valueSize > self.data.length) {
|
||||
self.hasError = YES;
|
||||
return 0;
|
||||
}
|
||||
[self.data getBytes:&value range:NSMakeRange(index, valueSize)];
|
||||
if (self.littleEndian) {
|
||||
return CFSwapInt32LittleToHost(value);
|
||||
} else {
|
||||
return CFSwapInt32BigToHost(value);
|
||||
}
|
||||
}
|
||||
|
||||
- (uint32_t)nextUInt32
|
||||
{
|
||||
uint32_t value = [self uint32AtIndex:self.cursor];
|
||||
self.cursor += sizeof(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
#pragma mark - UInt64
|
||||
|
||||
- (uint64_t)uint64AtIndex:(NSUInteger)index
|
||||
{
|
||||
uint64_t value;
|
||||
const size_t valueSize = sizeof(value);
|
||||
OWSAssertDebug(valueSize == 8);
|
||||
if (index + valueSize > self.data.length) {
|
||||
self.hasError = YES;
|
||||
return 0;
|
||||
}
|
||||
[self.data getBytes:&value range:NSMakeRange(index, valueSize)];
|
||||
if (self.littleEndian) {
|
||||
return CFSwapInt64LittleToHost(value);
|
||||
} else {
|
||||
return CFSwapInt64BigToHost(value);
|
||||
}
|
||||
}
|
||||
|
||||
- (uint64_t)nextUInt64
|
||||
{
|
||||
uint64_t value = [self uint64AtIndex:self.cursor];
|
||||
self.cursor += sizeof(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (BOOL)readZero:(NSUInteger)length
|
||||
{
|
||||
NSData *_Nullable subdata = [self readBytes:length];
|
||||
if (!subdata) {
|
||||
return NO;
|
||||
}
|
||||
uint8_t bytes[length];
|
||||
[subdata getBytes:bytes range:NSMakeRange(0, length)];
|
||||
for (unsigned i = 0; i < length; i++) {
|
||||
if (bytes[i] != 0) {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (nullable NSData *)readBytes:(NSUInteger)length
|
||||
{
|
||||
NSUInteger index = self.cursor;
|
||||
if (index + length > self.data.length) {
|
||||
self.hasError = YES;
|
||||
return nil;
|
||||
}
|
||||
NSData *_Nullable subdata = [self.data subdataWithRange:NSMakeRange(index, length)];
|
||||
self.cursor += length;
|
||||
return subdata;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -113,6 +113,13 @@ extension FixedWidthInteger {
|
||||
self = selfValue
|
||||
}
|
||||
|
||||
init?(littleEndianData: Data) {
|
||||
guard let (selfValue, _) = Self.from(littleEndianData: littleEndianData) else {
|
||||
return nil
|
||||
}
|
||||
self = selfValue
|
||||
}
|
||||
|
||||
/// Parses a big endian `Data` value into an integer.
|
||||
///
|
||||
/// If `bigEndianData.count` is larger than the size of the underlying
|
||||
@ -130,7 +137,28 @@ extension FixedWidthInteger {
|
||||
return (Self(bigEndian: bigEndianValue), count)
|
||||
}
|
||||
|
||||
/// Parses a little endian `Data` value into an integer.
|
||||
///
|
||||
/// If `littleEndianData.count` is larger than the size of the underlying
|
||||
/// integer, extra bytes are ignored.
|
||||
///
|
||||
/// - Parameter littleEndianData: The data for a big endian integer.
|
||||
/// - Returns: A tuple consisting of the integer itself and the number of
|
||||
/// bytes consumed from `littleEndianData`.
|
||||
static func from(littleEndianData: Data) -> (Self, byteCount: Int)? {
|
||||
var littleEndianValue = Self()
|
||||
let count = withUnsafeMutableBytes(of: &littleEndianValue) { littleEndianData.copyBytes(to: $0) }
|
||||
guard count == MemoryLayout<Self>.size else {
|
||||
return nil
|
||||
}
|
||||
return (Self(littleEndian: littleEndianValue), count)
|
||||
}
|
||||
|
||||
var bigEndianData: Data {
|
||||
return withUnsafeBytes(of: bigEndian) { Data($0) }
|
||||
}
|
||||
|
||||
public var littleEndianData: Data {
|
||||
return withUnsafeBytes(of: littleEndian) { Data($0) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -423,27 +423,20 @@ public class ProfileFetcherJob: NSObject {
|
||||
let profile = fetchedProfile.profile
|
||||
let serviceId = profile.serviceId
|
||||
|
||||
var givenName: String?
|
||||
var familyName: String?
|
||||
var bio: String?
|
||||
var bioEmoji: String?
|
||||
var paymentAddress: TSPaymentAddress?
|
||||
if let decryptedProfile = fetchedProfile.decryptedProfile {
|
||||
givenName = decryptedProfile.givenName?.nilIfEmpty
|
||||
familyName = decryptedProfile.familyName?.nilIfEmpty
|
||||
bio = decryptedProfile.bio?.nilIfEmpty
|
||||
bioEmoji = decryptedProfile.bioEmoji?.nilIfEmpty
|
||||
paymentAddress = decryptedProfile.paymentAddress
|
||||
}
|
||||
let givenName = fetchedProfile.decryptedProfile?.givenName
|
||||
let familyName = fetchedProfile.decryptedProfile?.familyName
|
||||
let bio = fetchedProfile.decryptedProfile?.bio
|
||||
let bioEmoji = fetchedProfile.decryptedProfile?.bioEmoji
|
||||
let paymentAddress = fetchedProfile.decryptedProfile?.paymentAddress(identityKey: fetchedProfile.identityKey)
|
||||
|
||||
if DebugFlags.internalLogging {
|
||||
let profileKeyDescription = fetchedProfile.profileKey?.keyData.hexadecimalString ?? "None"
|
||||
let hasAvatar = profile.avatarUrlPath != nil
|
||||
let hasProfileNameEncrypted = profile.profileNameEncrypted != nil
|
||||
let hasGivenName = givenName?.nilIfEmpty != nil
|
||||
let hasFamilyName = familyName?.nilIfEmpty != nil
|
||||
let hasBio = bio?.nilIfEmpty != nil
|
||||
let hasBioEmoji = bioEmoji?.nilIfEmpty != nil
|
||||
let hasGivenName = givenName != nil
|
||||
let hasFamilyName = familyName != nil
|
||||
let hasBio = bio != nil
|
||||
let hasBioEmoji = bioEmoji != nil
|
||||
let hasPaymentAddress = paymentAddress != nil
|
||||
let badges = fetchedProfile.profile.badges.map { "\"\($0.0.description)\"" }.joined(separator: "; ")
|
||||
|
||||
@ -576,13 +569,12 @@ public class ProfileFetcherJob: NSObject {
|
||||
|
||||
// MARK: -
|
||||
|
||||
public struct DecryptedProfile: Dependencies {
|
||||
public struct DecryptedProfile {
|
||||
public let givenName: String?
|
||||
public let familyName: String?
|
||||
public let bio: String?
|
||||
public let bioEmoji: String?
|
||||
public let paymentAddressData: Data?
|
||||
public let identityKey: IdentityKey
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
@ -591,45 +583,37 @@ public struct FetchedProfile {
|
||||
let profile: SignalServiceProfile
|
||||
let profileKey: OWSAES256Key?
|
||||
public let decryptedProfile: DecryptedProfile?
|
||||
public let identityKey: IdentityKey
|
||||
|
||||
init(profile: SignalServiceProfile, profileKey: OWSAES256Key?) {
|
||||
self.profile = profile
|
||||
self.profileKey = profileKey
|
||||
self.decryptedProfile = Self.decrypt(profile: profile, profileKey: profileKey)
|
||||
self.identityKey = profile.identityKey
|
||||
}
|
||||
|
||||
private static func decrypt(profile: SignalServiceProfile, profileKey: OWSAES256Key?) -> DecryptedProfile? {
|
||||
guard let profileKey = profileKey else {
|
||||
guard let profileKey else {
|
||||
return nil
|
||||
}
|
||||
var givenName: String?
|
||||
var familyName: String?
|
||||
var bio: String?
|
||||
var bioEmoji: String?
|
||||
var paymentAddressData: Data?
|
||||
let profileName = profile.profileNameEncrypted.flatMap {
|
||||
let nameComponents = profile.profileNameEncrypted.flatMap {
|
||||
OWSUserProfile.decrypt(profileNameData: $0, profileKey: profileKey)
|
||||
}
|
||||
if let profileName {
|
||||
givenName = profileName.givenName
|
||||
familyName = profileName.familyName
|
||||
let bio = profile.bioEncrypted.flatMap {
|
||||
OWSUserProfile.decrypt(profileStringData: $0, profileKey: profileKey)
|
||||
}
|
||||
if let bioEncrypted = profile.bioEncrypted {
|
||||
bio = OWSUserProfile.decrypt(profileStringData: bioEncrypted, profileKey: profileKey)
|
||||
let bioEmoji = profile.bioEmojiEncrypted.flatMap {
|
||||
OWSUserProfile.decrypt(profileStringData: $0, profileKey: profileKey)
|
||||
}
|
||||
if let bioEmojiEncrypted = profile.bioEmojiEncrypted {
|
||||
bioEmoji = OWSUserProfile.decrypt(profileStringData: bioEmojiEncrypted, profileKey: profileKey)
|
||||
}
|
||||
if let paymentAddressEncrypted = profile.paymentAddressEncrypted {
|
||||
paymentAddressData = OWSUserProfile.decrypt(profileData: paymentAddressEncrypted, profileKey: profileKey)
|
||||
let paymentAddressData = profile.paymentAddressEncrypted.flatMap {
|
||||
OWSUserProfile.decrypt(profileData: $0, profileKey: profileKey)
|
||||
}
|
||||
return DecryptedProfile(
|
||||
givenName: givenName,
|
||||
familyName: familyName,
|
||||
givenName: nameComponents?.givenName,
|
||||
familyName: nameComponents?.familyName,
|
||||
bio: bio,
|
||||
bioEmoji: bioEmoji,
|
||||
paymentAddressData: paymentAddressData,
|
||||
identityKey: profile.identityKey
|
||||
paymentAddressData: paymentAddressData
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -637,28 +621,23 @@ public struct FetchedProfile {
|
||||
// MARK: -
|
||||
|
||||
public extension DecryptedProfile {
|
||||
|
||||
var paymentAddress: TSPaymentAddress? {
|
||||
guard paymentsHelper.arePaymentsEnabled else {
|
||||
return nil
|
||||
}
|
||||
guard let paymentAddressDataWithLength = paymentAddressData else {
|
||||
func paymentAddress(identityKey: IdentityKey) -> TSPaymentAddress? {
|
||||
guard var paymentAddressData = paymentAddressData else {
|
||||
return nil
|
||||
}
|
||||
|
||||
do {
|
||||
let byteParser = ByteParser(data: paymentAddressDataWithLength, littleEndian: true)
|
||||
let length = byteParser.nextUInt32()
|
||||
guard length > 0 else {
|
||||
guard let (dataLength, dataLengthCount) = UInt32.from(littleEndianData: paymentAddressData) else {
|
||||
return nil
|
||||
}
|
||||
guard let paymentAddressDataWithoutLength = byteParser.readBytes(UInt(length)) else {
|
||||
owsFailDebug("Invalid payment address.")
|
||||
paymentAddressData = paymentAddressData.dropFirst(dataLengthCount)
|
||||
paymentAddressData = paymentAddressData.prefix(Int(dataLength))
|
||||
guard paymentAddressData.count == dataLength else {
|
||||
owsFailDebug("Invalid paymentAddressData.")
|
||||
return nil
|
||||
}
|
||||
let proto = try SSKProtoPaymentAddress(serializedData: paymentAddressDataWithoutLength)
|
||||
let paymentAddress = try TSPaymentAddress.fromProto(proto, identityKey: identityKey)
|
||||
return paymentAddress
|
||||
let proto = try SSKProtoPaymentAddress(serializedData: paymentAddressData)
|
||||
return try TSPaymentAddress.fromProto(proto, identityKey: identityKey)
|
||||
} catch {
|
||||
owsFailDebug("Error: \(error)")
|
||||
return nil
|
||||
|
||||
@ -336,9 +336,11 @@ public extension PaymentsImpl {
|
||||
|
||||
// We don't need to persist this value in the cache; the ProfileFetcherJob
|
||||
// will take care of that.
|
||||
guard let paymentAddress = decryptedProfile.paymentAddress,
|
||||
paymentAddress.isValid,
|
||||
paymentAddress.currency == .mobileCoin else {
|
||||
guard
|
||||
let paymentAddress = decryptedProfile.paymentAddress(identityKey: fetchedProfile.identityKey),
|
||||
paymentAddress.isValid,
|
||||
paymentAddress.currency == .mobileCoin
|
||||
else {
|
||||
throw PaymentsError.userHasNoPublicAddress
|
||||
}
|
||||
do {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user