diff --git a/OpenVPN Adapter/OpenVPNPrivateKey.h b/OpenVPN Adapter/OpenVPNPrivateKey.h new file mode 100644 index 0000000..9157862 --- /dev/null +++ b/OpenVPN Adapter/OpenVPNPrivateKey.h @@ -0,0 +1,26 @@ +// +// OpenVPNPrivateKey.h +// OpenVPN Adapter +// +// Created by Sergey Abramchuk on 07.09.17. +// +// + +#import + +@interface OpenVPNPrivateKey : NSObject + ++ (nullable OpenVPNPrivateKey *)keyWithPEM:(nonnull NSData *)pemData + password:(nullable NSString *)password + error:(out NSError * __nullable * __nullable)error; + ++ (nullable OpenVPNPrivateKey *)keyWithDER:(nonnull NSData *)derData + password:(nullable NSString *)password + error:(out NSError * __nullable * __nullable)error; + +- (nonnull instancetype) __unavailable init; + +- (nullable NSData *)pemData:(out NSError * __nullable * __nullable)error; +- (nullable NSData *)derData:(out NSError * __nullable * __nullable)error; + +@end diff --git a/OpenVPN Adapter/OpenVPNPrivateKey.m b/OpenVPN Adapter/OpenVPNPrivateKey.m new file mode 100644 index 0000000..924b425 --- /dev/null +++ b/OpenVPN Adapter/OpenVPNPrivateKey.m @@ -0,0 +1,49 @@ +// +// OpenVPNPrivateKey.m +// OpenVPN Adapter +// +// Created by Sergey Abramchuk on 07.09.17. +// +// + +#import + +#import "NSError+Message.h" +#import "OpenVPNError.h" +#import "OpenVPNPrivateKey.h" + +@interface OpenVPNPrivateKey () + +@property (nonatomic, assign) mbedtls_pk_context *key; + +@end + +@implementation OpenVPNPrivateKey + +- (instancetype)init { + self = [super init]; + if (self) { + self.key = malloc(sizeof(mbedtls_pk_context)); + mbedtls_pk_init(self.key); + } + return self; +} + ++ (nullable OpenVPNPrivateKey *)keyWithPEM:(NSData *)pemData password:(NSString *)password error:(out NSError **)error { + OpenVPNPrivateKey *key = [OpenVPNPrivateKey new]; + + return key; +} + ++ (nullable OpenVPNPrivateKey *)keyWithDER:(NSData *)derData password:(NSString *)password error:(out NSError **)error { + OpenVPNPrivateKey *key = [OpenVPNPrivateKey new]; + + return key; +} + +- (void)dealloc { + mbedtls_pk_free(self.key); + free(self.key); +} + +@end