0
0
mirror of https://github.com/signalapp/libsignal.git synced 2024-09-20 20:03:07 +02:00

Merge pull request #13 from signalapp/jrose/minor-tweaks

Minor tweaks to help integration with the existing iOS client
This commit is contained in:
Jordan Rose 2020-10-08 13:22:58 -07:00 committed by GitHub
commit abfdc320a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 12 deletions

View File

@ -1,11 +1,11 @@
import SignalFfi
public class ProtocolAddress: ClonableHandleOwner {
public init(name: String, device_id: UInt32) throws {
public init(name: String, deviceId: UInt32) throws {
var handle: OpaquePointer?
try checkError(signal_address_new(&handle,
name,
device_id))
deviceId))
super.init(owned: handle!)
}

View File

@ -12,6 +12,11 @@ public class InMemorySignalProtocolStore: IdentityKeyStore, PreKeyStore, SignedP
deviceId = UInt32.random(in: 0...65535)
}
public init(identity: IdentityKeyPair, deviceId: UInt32) {
self.privateKey = identity
self.deviceId = deviceId
}
public func identityKeyPair(context: UnsafeMutableRawPointer?) throws -> IdentityKeyPair {
return privateKey
}

View File

@ -20,13 +20,10 @@ public struct IdentityKeyPair {
public let publicKey: PublicKey
public let privateKey: PrivateKey
private init() throws {
privateKey = try PrivateKey.generate()
publicKey = try privateKey.publicKey()
}
public static func generate() throws -> IdentityKeyPair {
return try IdentityKeyPair()
let privateKey = try PrivateKey.generate()
let publicKey = try privateKey.publicKey()
return IdentityKeyPair(publicKey: publicKey, privateKey: privateKey)
}
public init(bytes: [UInt8]) throws {
@ -38,6 +35,11 @@ public struct IdentityKeyPair {
privateKey = PrivateKey(owned: privkeyPtr!)
}
public init(publicKey: PublicKey, privateKey: PrivateKey) {
self.publicKey = publicKey
self.privateKey = privateKey
}
public func serialize() throws -> [UInt8] {
return try invokeFnReturningArray {
signal_identitykeypair_serialize($0, $1, publicKey.nativeHandle, privateKey.nativeHandle)

View File

@ -28,7 +28,7 @@ class PublicAPITests: XCTestCase {
}
func testAddress() {
let addr = try! ProtocolAddress(name: "addr1", device_id: 5)
let addr = try! ProtocolAddress(name: "addr1", deviceId: 5)
XCTAssertEqual(addr.name, "addr1")
XCTAssertEqual(addr.deviceId, 5)
}
@ -179,7 +179,7 @@ class PublicAPITests: XCTestCase {
func testGroupCipher() {
let sender = try! ProtocolAddress(name: "+14159999111", device_id: 4)
let sender = try! ProtocolAddress(name: "+14159999111", deviceId: 4)
let group_id = try! SenderKeyName(groupName: "summer camp", sender: sender)
let a_store = try! InMemorySignalProtocolStore()
@ -203,8 +203,8 @@ class PublicAPITests: XCTestCase {
}
func testSessionCipher() {
let alice_address = try! ProtocolAddress(name: "+14151111111", device_id: 1)
let bob_address = try! ProtocolAddress(name: "+14151111112", device_id: 1)
let alice_address = try! ProtocolAddress(name: "+14151111111", deviceId: 1)
let bob_address = try! ProtocolAddress(name: "+14151111112", deviceId: 1)
let alice_store = try! InMemorySignalProtocolStore()
let bob_store = try! InMemorySignalProtocolStore()