forked from signalapp/SignalProtocolKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhisperMessageSerialization.m
62 lines (47 loc) · 2.76 KB
/
WhisperMessageSerialization.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <AxolotlKit/WhisperMessage.h>
#import <Curve25519Kit/Curve25519.h>
#import <XCTest/XCTest.h>
@interface WhisperMessageSerialization : XCTestCase
@end
@implementation WhisperMessageSerialization
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testWhisperMessage {
ECKeyPair *keyPair = [Curve25519 generateKeyPair];
ECKeyPair *fakeMacKey = [Curve25519 generateKeyPair];
int counter = 0;
NSData *cipherText = [@"I'm not really ciphertext" dataUsingEncoding:NSUTF8StringEncoding];
ECKeyPair *senderIdentityKey = [Curve25519 generateKeyPair];
ECKeyPair *receiverIdentityKey = [Curve25519 generateKeyPair];
WhisperMessage *message = [[WhisperMessage alloc] init_throws_withVersion:3
macKey:fakeMacKey.publicKey
senderRatchetKey:keyPair.publicKey
counter:counter
previousCounter:0
cipherText:cipherText
senderIdentityKey:senderIdentityKey.publicKey
receiverIdentityKey:receiverIdentityKey.publicKey];
WhisperMessage *deserializedMessage = [[WhisperMessage alloc] init_throws_withData:message.serialized];
XCTAssert([[message.serialized subdataWithRange:NSMakeRange(0, message.serialized.length-8)] isEqualToData:[deserializedMessage.serialized subdataWithRange:NSMakeRange(0, deserializedMessage.serialized.length-8)]]);
[message throws_verifyMacWithVersion:3
senderIdentityKey:senderIdentityKey.publicKey
receiverIdentityKey:receiverIdentityKey.publicKey
macKey:fakeMacKey.publicKey];
[deserializedMessage throws_verifyMacWithVersion:3
senderIdentityKey:senderIdentityKey.publicKey
receiverIdentityKey:receiverIdentityKey.publicKey
macKey:fakeMacKey.publicKey];
XCTAssert([message.cipherText isEqualToData:deserializedMessage.cipherText]);
XCTAssert(message.version == deserializedMessage.version);
XCTAssert([message.serialized isEqualToData:deserializedMessage.serialized]);
}
@end