fix padding calculation
// FREEBIE
This commit is contained in:
parent
a5660f4db4
commit
6dea4c9fef
@ -17,6 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@property (nonatomic, readonly) NSString *verificationForRecipientId;
|
||||
|
||||
@property (nonatomic, readonly) size_t paddingBytesLength;
|
||||
@property (nonatomic, readonly) size_t unpaddedVerifiedLength;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@ -26,9 +26,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
identityKey:(NSData *)identityKey
|
||||
verificationForRecipientId:(NSString *)verificationForRecipientId
|
||||
{
|
||||
|
||||
OWSAssert(identityKey.length == kIdentityKeyLength);
|
||||
OWSAssert(verificationForRecipientId.length > 0);
|
||||
|
||||
// we only sync user's marking as un/verified. Never sync the conflicted state, the sibling device
|
||||
// will figure that out on it's own.
|
||||
OWSAssert(verificationState != OWSVerificationStateNoLongerVerified);
|
||||
@ -51,6 +51,13 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (OWSSignalServiceProtosSyncMessageBuilder *)syncMessageBuilder
|
||||
{
|
||||
OWSAssert(self.identityKey.length == kIdentityKeyLength);
|
||||
OWSAssert(self.verificationForRecipientId.length > 0);
|
||||
|
||||
// we only sync user's marking as un/verified. Never sync the conflicted state, the sibling device
|
||||
// will figure that out on it's own.
|
||||
OWSAssert(self.verificationState != OWSVerificationStateNoLongerVerified);
|
||||
|
||||
OWSSignalServiceProtosSyncMessageBuilder *syncMessageBuilder = [OWSSignalServiceProtosSyncMessageBuilder new];
|
||||
|
||||
OWSSignalServiceProtosVerifiedBuilder *verifiedBuilder = [OWSSignalServiceProtosVerifiedBuilder new];
|
||||
@ -66,6 +73,23 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
return syncMessageBuilder;
|
||||
}
|
||||
|
||||
- (size_t)unpaddedVerifiedLength
|
||||
{
|
||||
OWSAssert(self.identityKey.length == kIdentityKeyLength);
|
||||
OWSAssert(self.verificationForRecipientId.length > 0);
|
||||
|
||||
// we only sync user's marking as un/verified. Never sync the conflicted state, the sibling device
|
||||
// will figure that out on it's own.
|
||||
OWSAssert(self.verificationState != OWSVerificationStateNoLongerVerified);
|
||||
|
||||
OWSSignalServiceProtosVerifiedBuilder *verifiedBuilder = [OWSSignalServiceProtosVerifiedBuilder new];
|
||||
verifiedBuilder.destination = self.verificationForRecipientId;
|
||||
verifiedBuilder.identityKey = self.identityKey;
|
||||
verifiedBuilder.state = OWSVerificationStateToProtoState(self.verificationState);
|
||||
|
||||
return [verifiedBuilder build].data.length;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@ -40,9 +40,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
OWSSignalServiceProtosContentBuilder *contentBuilder = [OWSSignalServiceProtosContentBuilder new];
|
||||
OWSSignalServiceProtosNullMessageBuilder *nullMessageBuilder = [OWSSignalServiceProtosNullMessageBuilder new];
|
||||
|
||||
NSUInteger contentLength = self.verificationStateSyncMessage.buildPlainTextData.length;
|
||||
contentLength -= self.verificationStateSyncMessage.paddingBytesLength;
|
||||
|
||||
NSUInteger contentLength = self.verificationStateSyncMessage.unpaddedVerifiedLength;
|
||||
|
||||
OWSAssert(self.verificationStateSyncMessage.paddingBytesLength > 0);
|
||||
contentLength += self.verificationStateSyncMessage.paddingBytesLength;
|
||||
|
||||
OWSAssert(contentLength > 0)
|
||||
|
||||
nullMessageBuilder.padding = [Cryptography generateRandomBytes:contentLength];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user