mirror of https://github.com/oxen-io/session-ios
Elaborate request factory.
parent
3acdd84398
commit
c2f092018c
@ -1,21 +0,0 @@
|
|||||||
//
|
|
||||||
// TSRegisterPrekeys.h
|
|
||||||
// TextSecureiOS
|
|
||||||
//
|
|
||||||
// Created by Christine Corbett Moran on 10/17/13.
|
|
||||||
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "TSRequest.h"
|
|
||||||
@class TSECKeyPair;
|
|
||||||
@class SignedPreKeyRecord;
|
|
||||||
@class PreKeyRecord;
|
|
||||||
|
|
||||||
@interface TSRegisterPrekeysRequest : TSRequest
|
|
||||||
|
|
||||||
- (id)initWithPrekeyArray:(NSArray *)prekeys
|
|
||||||
identityKey:(NSData *)identityKeyPublic
|
|
||||||
signedPreKeyRecord:(SignedPreKeyRecord *)signedRecord
|
|
||||||
preKeyLastResort:(PreKeyRecord *)lastResort;
|
|
||||||
|
|
||||||
@end
|
|
@ -1,60 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "TSRegisterPrekeysRequest.h"
|
|
||||||
#import "TSConstants.h"
|
|
||||||
#import <AxolotlKit/NSData+keyVersionByte.h>
|
|
||||||
#import <AxolotlKit/PreKeyRecord.h>
|
|
||||||
#import <AxolotlKit/SignedPreKeyStore.h>
|
|
||||||
#import <Curve25519Kit/Curve25519.h>
|
|
||||||
|
|
||||||
@implementation TSRegisterPrekeysRequest
|
|
||||||
|
|
||||||
- (id)initWithPrekeyArray:(NSArray *)prekeys
|
|
||||||
identityKey:(NSData *)identityKeyPublic
|
|
||||||
signedPreKeyRecord:(SignedPreKeyRecord *)signedRecord
|
|
||||||
preKeyLastResort:(PreKeyRecord *)lastResort {
|
|
||||||
self = [super initWithURL:[NSURL URLWithString:textSecureKeysAPI]];
|
|
||||||
if (!self) {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.HTTPMethod = @"PUT";
|
|
||||||
|
|
||||||
NSString *publicIdentityKey = [[identityKeyPublic prependKeyType] base64EncodedStringWithOptions:0];
|
|
||||||
NSMutableArray *serializedPrekeyList = [NSMutableArray array];
|
|
||||||
|
|
||||||
for (PreKeyRecord *preKey in prekeys) {
|
|
||||||
[serializedPrekeyList addObject:[self dictionaryFromPreKey:preKey]];
|
|
||||||
}
|
|
||||||
|
|
||||||
NSDictionary *serializedKeyRegistrationParameters = @{
|
|
||||||
@"preKeys" : serializedPrekeyList,
|
|
||||||
@"lastResortKey" : [self dictionaryFromPreKey:lastResort],
|
|
||||||
@"signedPreKey" : [self dictionaryFromSignedPreKey:signedRecord],
|
|
||||||
@"identityKey" : publicIdentityKey
|
|
||||||
};
|
|
||||||
|
|
||||||
self.parameters = [serializedKeyRegistrationParameters mutableCopy];
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (NSDictionary *)dictionaryFromPreKey:(PreKeyRecord *)preKey {
|
|
||||||
return @{
|
|
||||||
@"keyId" : [NSNumber numberWithInt:preKey.Id],
|
|
||||||
@"publicKey" : [[preKey.keyPair.publicKey prependKeyType] base64EncodedStringWithOptions:0],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSDictionary *)dictionaryFromSignedPreKey:(SignedPreKeyRecord *)preKey {
|
|
||||||
return @{
|
|
||||||
@"keyId" : [NSNumber numberWithInt:preKey.Id],
|
|
||||||
@"publicKey" : [[preKey.keyPair.publicKey prependKeyType] base64EncodedStringWithOptions:0],
|
|
||||||
@"signature" : [preKey.signature base64EncodedStringWithOptions:0]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
@ -1,14 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "TSRequest.h"
|
|
||||||
|
|
||||||
@class SignedPreKeyRecord;
|
|
||||||
@class PreKeyRecord;
|
|
||||||
|
|
||||||
@interface TSRegisterSignedPrekeyRequest : TSRequest
|
|
||||||
|
|
||||||
- (id)initWithSignedPreKeyRecord:(SignedPreKeyRecord *)signedRecord;
|
|
||||||
|
|
||||||
@end
|
|
@ -1,39 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "TSRegisterSignedPrekeyRequest.h"
|
|
||||||
#import "TSConstants.h"
|
|
||||||
#import <AxolotlKit/NSData+keyVersionByte.h>
|
|
||||||
#import <AxolotlKit/PreKeyRecord.h>
|
|
||||||
#import <AxolotlKit/SignedPreKeyStore.h>
|
|
||||||
#import <Curve25519Kit/Curve25519.h>
|
|
||||||
|
|
||||||
@implementation TSRegisterSignedPrekeyRequest
|
|
||||||
|
|
||||||
- (id)initWithSignedPreKeyRecord:(SignedPreKeyRecord *)signedRecord
|
|
||||||
{
|
|
||||||
self = [super initWithURL:[NSURL URLWithString:textSecureSignedKeysAPI]];
|
|
||||||
if (!self) {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.HTTPMethod = @"PUT";
|
|
||||||
|
|
||||||
NSDictionary *serializedKeyRegistrationParameters = [self dictionaryFromSignedPreKey:signedRecord];
|
|
||||||
|
|
||||||
self.parameters = [serializedKeyRegistrationParameters mutableCopy];
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSDictionary *)dictionaryFromSignedPreKey:(SignedPreKeyRecord *)preKey
|
|
||||||
{
|
|
||||||
return @{
|
|
||||||
@"keyId" : [NSNumber numberWithInt:preKey.Id],
|
|
||||||
@"publicKey" : [[preKey.keyPair.publicKey prependKeyType] base64EncodedStringWithOptions:0],
|
|
||||||
@"signature" : [preKey.signature base64EncodedStringWithOptions:0]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
@ -1,19 +0,0 @@
|
|||||||
//
|
|
||||||
// TSSubmitMessageRequest.h
|
|
||||||
// TextSecureiOS
|
|
||||||
//
|
|
||||||
// Created by Christine Corbett Moran on 11/30/13.
|
|
||||||
// Copyright (c) 2013 Open Whisper Systems. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "TSConstants.h"
|
|
||||||
#import "TSRequest.h"
|
|
||||||
|
|
||||||
@interface TSSubmitMessageRequest : TSRequest
|
|
||||||
|
|
||||||
- (TSRequest *)initWithRecipient:(NSString *)contactRegisteredID
|
|
||||||
messages:(NSArray *)messages
|
|
||||||
relay:(NSString *)relay
|
|
||||||
timeStamp:(uint64_t)timeStamp;
|
|
||||||
|
|
||||||
@end
|
|
@ -1,34 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "TSSubmitMessageRequest.h"
|
|
||||||
#import "TSConstants.h"
|
|
||||||
|
|
||||||
@implementation TSSubmitMessageRequest
|
|
||||||
|
|
||||||
- (TSRequest *)initWithRecipient:(NSString *)contactRegisteredID
|
|
||||||
messages:(NSArray *)messages
|
|
||||||
relay:(NSString *)relay
|
|
||||||
timeStamp:(uint64_t)timeStamp {
|
|
||||||
self =
|
|
||||||
[super initWithURL:[NSURL URLWithString:[textSecureMessagesAPI stringByAppendingString:contactRegisteredID]]];
|
|
||||||
if (!self) {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSMutableDictionary *parameters = [@{
|
|
||||||
@"messages" : messages,
|
|
||||||
@"timestamp" : @(timeStamp),
|
|
||||||
} mutableCopy];
|
|
||||||
|
|
||||||
if (relay) {
|
|
||||||
parameters[@"relay"] = relay;
|
|
||||||
}
|
|
||||||
|
|
||||||
[self setHTTPMethod:@"PUT"];
|
|
||||||
self.parameters = parameters;
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
Loading…
Reference in New Issue