aboutsummaryrefslogtreecommitdiff
path: root/xcode/OLMKit/OLMUtility.m
diff options
context:
space:
mode:
authormanuroe <manu@matrix.org>2016-10-17 15:47:52 +0200
committermanuroe <manu@matrix.org>2016-10-17 15:47:52 +0200
commita9be04fa4b53e7012406a9a89596e94b65947c20 (patch)
tree7815c6b2b1f276aecb32e91aba8f9ce80b03cc74 /xcode/OLMKit/OLMUtility.m
parent4a2aac5800dacb3de935f6594e4d213087cb7cb5 (diff)
OLMKit: Add [OLMUtility sha256:]
Diffstat (limited to 'xcode/OLMKit/OLMUtility.m')
-rw-r--r--xcode/OLMKit/OLMUtility.m21
1 files changed, 20 insertions, 1 deletions
diff --git a/xcode/OLMKit/OLMUtility.m b/xcode/OLMKit/OLMUtility.m
index 041da2f..292fc21 100644
--- a/xcode/OLMKit/OLMUtility.m
+++ b/xcode/OLMKit/OLMUtility.m
@@ -50,6 +50,25 @@
return self;
}
+- (NSString *)sha256:(NSData *)message {
+ size_t length = olm_sha256_length(_utility);
+
+ NSMutableData *shaData = [NSMutableData dataWithLength:length];
+ if (!shaData) {
+ return nil;
+ }
+
+ size_t result = olm_sha256(_utility, message.bytes, message.length, shaData.mutableBytes, shaData.length);
+ if (result == olm_error()) {
+ const char *error = olm_utility_last_error(_utility);
+ NSAssert(NO, @"olm_sha256 error: %s", error);
+ return nil;
+ }
+
+ NSString *sha = [[NSString alloc] initWithData:shaData encoding:NSUTF8StringEncoding];
+ return sha;
+}
+
- (BOOL)verifyEd25519Signature:(NSString*)signature key:(NSString*)key message:(NSData*)message error:(NSError**)error {
NSData *keyData = [key dataUsingEncoding:NSUTF8StringEncoding];
@@ -61,7 +80,7 @@
signatureData.bytes, signatureData.length
);
- if (result < 0 || result == (size_t)-1) {
+ if (result == olm_error()) {
if (error) {
NSDictionary *userInfo = @{NSLocalizedFailureReasonErrorKey: [NSString stringWithUTF8String:olm_utility_last_error(_utility)]};