2016-11-17 15:50:23 +01:00
|
|
|
/*
|
|
|
|
Copyright 2016 Chris Ballinger
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
|
|
|
Copyright 2016 Vector Creations Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2016-04-09 02:24:41 +02:00
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
2016-11-14 16:54:51 +01:00
|
|
|
FOUNDATION_EXPORT NSString *const OLMErrorDomain;
|
|
|
|
|
2016-04-09 02:24:41 +02:00
|
|
|
@interface OLMUtility : NSObject
|
|
|
|
|
2016-10-17 15:47:52 +02:00
|
|
|
/**
|
|
|
|
Calculate the SHA-256 hash of the input and encodes it as base64.
|
|
|
|
|
|
|
|
@param message the message to hash.
|
|
|
|
@return the base64-encoded hash value.
|
|
|
|
*/
|
|
|
|
- (NSString*)sha256:(NSData*)message;
|
|
|
|
|
2016-09-28 16:07:39 +02:00
|
|
|
/**
|
|
|
|
Verify an ed25519 signature.
|
|
|
|
|
2016-10-14 15:57:12 +02:00
|
|
|
@param signature the base64-encoded signature to be checked.
|
2016-09-28 16:07:39 +02:00
|
|
|
@param key the ed25519 key.
|
|
|
|
@param message the message which was signed.
|
2018-06-25 17:57:51 +02:00
|
|
|
@param error if there is a problem with the verification.
|
2016-09-28 16:07:39 +02:00
|
|
|
If the key was too small then the message will be "OLM.INVALID_BASE64".
|
|
|
|
If the signature was invalid then the message will be "OLM.BAD_MESSAGE_MAC".
|
|
|
|
|
|
|
|
@return YES if valid.
|
|
|
|
*/
|
2016-10-14 15:57:12 +02:00
|
|
|
- (BOOL)verifyEd25519Signature:(NSString*)signature key:(NSString*)key message:(NSData*)message error:(NSError**)error;
|
2016-09-28 16:07:39 +02:00
|
|
|
|
2016-04-09 23:00:30 +02:00
|
|
|
+ (NSMutableData*) randomBytesOfLength:(NSUInteger)length;
|
2016-04-09 02:24:41 +02:00
|
|
|
|
|
|
|
@end
|