Merge branch 'charlesmchen/ud7'
This commit is contained in:
commit
954cbfa767
@ -8,9 +8,11 @@ import Foundation
|
||||
// https://github.com/signalapp/libsignal-protocol-java/blob/87fae0f98332e98a32bbb82515428b4edeb4181f/java/src/main/java/org/whispersystems/libsignal/ecc/ECPrivateKey.java
|
||||
@objc public class ECPrivateKey: NSObject {
|
||||
|
||||
@objc public let keyData: Data
|
||||
@objc
|
||||
public let keyData: Data
|
||||
|
||||
@objc public init(keyData: Data) throws {
|
||||
@objc
|
||||
public init(keyData: Data) throws {
|
||||
guard keyData.count == ECCKeyLength else {
|
||||
throw SMKError.assertionError(description: "\(ECPrivateKey.logTag) key has invalid length")
|
||||
}
|
||||
|
||||
@ -8,9 +8,11 @@ import Foundation
|
||||
// https://github.com/signalapp/libsignal-protocol-java/blob/87fae0f98332e98a32bbb82515428b4edeb4181f/java/src/main/java/org/whispersystems/libsignal/ecc/DjbECPublicKey.java
|
||||
@objc public class ECPublicKey: NSObject {
|
||||
|
||||
@objc
|
||||
public static let keyTypeDJB: UInt8 = 0x05
|
||||
|
||||
@objc public let keyData: Data
|
||||
@objc
|
||||
public let keyData: Data
|
||||
|
||||
@objc
|
||||
public init(keyData: Data) throws {
|
||||
|
||||
@ -73,6 +73,24 @@ private class SMKStaticKeys: NSObject {
|
||||
|
||||
// MARK: -
|
||||
|
||||
@objc
|
||||
public class SMKDecryptResult: NSObject {
|
||||
|
||||
@objc public let senderRecipientId: String
|
||||
@objc public let senderDeviceId: Int
|
||||
@objc public let paddedPayload: Data
|
||||
|
||||
init(senderRecipientId: String,
|
||||
senderDeviceId: Int,
|
||||
paddedPayload: Data) {
|
||||
self.senderRecipientId = senderRecipientId
|
||||
self.senderDeviceId = senderDeviceId
|
||||
self.paddedPayload = paddedPayload
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
||||
@objc public class SMKSecretSessionCipher: NSObject {
|
||||
|
||||
private let kUDPrefixString = "UnidentifiedDelivery"
|
||||
@ -100,11 +118,12 @@ private class SMKStaticKeys: NSObject {
|
||||
|
||||
// public byte[] encrypt(SignalProtocolAddress destinationAddress, SenderCertificate senderCertificate, byte[]
|
||||
// paddedPlaintext)
|
||||
@objc public func encryptMessage(recipientId: String,
|
||||
deviceId: Int32,
|
||||
paddedPlaintext: Data,
|
||||
senderCertificate: SMKSenderCertificate,
|
||||
protocolContext: Any?) throws -> Data {
|
||||
@objc
|
||||
public func encryptMessage(recipientId: String,
|
||||
deviceId: Int32,
|
||||
paddedPlaintext: Data,
|
||||
senderCertificate: SMKSenderCertificate,
|
||||
protocolContext: Any?) throws -> Data {
|
||||
guard recipientId.count > 0 else {
|
||||
throw SMKError.assertionError(description: "\(SMKSecretSessionCipher.logTag) invalid recipientId")
|
||||
}
|
||||
@ -211,12 +230,11 @@ private class SMKStaticKeys: NSObject {
|
||||
// ProtocolNoSessionException, ProtocolLegacyMessageException,
|
||||
// ProtocolInvalidVersionException, ProtocolDuplicateMessageException,
|
||||
// ProtocolInvalidKeyIdException, ProtocolUntrustedIdentityException
|
||||
@objc
|
||||
public func decryptMessage(certificateValidator: SMKCertificateValidator,
|
||||
cipherTextData: Data,
|
||||
timestamp: UInt64,
|
||||
protocolContext: Any?) throws -> (senderRecipientId: String,
|
||||
senderDeviceId: Int,
|
||||
paddedPayload: Data) {
|
||||
protocolContext: Any?) throws -> SMKDecryptResult {
|
||||
|
||||
guard timestamp > 0 else {
|
||||
throw SMKError.assertionError(description: "\(logTag) invalid timestamp")
|
||||
@ -299,7 +317,7 @@ private class SMKStaticKeys: NSObject {
|
||||
guard senderDeviceId >= 0 && senderDeviceId <= INT_MAX else {
|
||||
throw SMKError.assertionError(description: "\(logTag) Invalid senderDeviceId.")
|
||||
}
|
||||
return (senderRecipientId: senderRecipientId, senderDeviceId: Int(senderDeviceId), paddedPayload: paddedMessagePlaintext)
|
||||
return SMKDecryptResult(senderRecipientId: senderRecipientId, senderDeviceId: Int(senderDeviceId), paddedPayload: paddedMessagePlaintext)
|
||||
}
|
||||
|
||||
// MARK: - Encrypt
|
||||
|
||||
Loading…
Reference in New Issue
Block a user