diff --git a/OpenVPN Adapter/OpenVPNCertificate.h b/OpenVPN Adapter/OpenVPNCertificate.h index 4cbb7bd..fb1c7f1 100644 --- a/OpenVPN Adapter/OpenVPNCertificate.h +++ b/OpenVPN Adapter/OpenVPNCertificate.h @@ -11,14 +11,14 @@ @interface OpenVPNCertificate : NSObject + (nullable OpenVPNCertificate *)certificateWithPEM:(nonnull NSData *)pemData - error:(out NSError * __nullable * __nullable)error; + error:(out NSError * _Nullable * _Nullable)error; + (nullable OpenVPNCertificate *)certificateWithDER:(nonnull NSData *)derData - error:(out NSError * __nullable * __nullable)error; + error:(out NSError * _Nullable * _Nullable)error; -- (nonnull instancetype) __unavailable init; +- (nonnull instancetype) init NS_UNAVAILABLE; -- (nullable NSData *)pemData:(out NSError * __nullable * __nullable)error; -- (nullable NSData *)derData:(out NSError * __nullable * __nullable)error; +- (nullable NSData *)pemData:(out NSError * _Nullable * _Nullable)error; +- (nullable NSData *)derData:(out NSError * _Nullable * _Nullable)error; @end diff --git a/OpenVPN Adapter/OpenVPNCertificate.m b/OpenVPN Adapter/OpenVPNCertificate.m index f0c70f7..826792e 100644 --- a/OpenVPN Adapter/OpenVPNCertificate.m +++ b/OpenVPN Adapter/OpenVPNCertificate.m @@ -7,8 +7,8 @@ // #import "OpenVPNCertificate.h" -#import -#import +#include +#include #import "NSError+OpenVPNError.h" @@ -20,16 +20,6 @@ @implementation OpenVPNCertificate -- (instancetype)init -{ - self = [super init]; - if (self) { - self.crt = malloc(sizeof(mbedtls_x509_crt)); - mbedtls_x509_crt_init(self.crt); - } - return self; -} - + (OpenVPNCertificate *)certificateWithPEM:(NSData *)pemData error:(out NSError **)error { OpenVPNCertificate *certificate = [OpenVPNCertificate new]; @@ -62,6 +52,15 @@ return certificate; } +- (instancetype)init +{ + if (self = [super init]) { + _crt = malloc(sizeof(mbedtls_x509_crt)); + mbedtls_x509_crt_init(_crt); + } + return self; +} + - (NSData *)pemData:(out NSError **)error { NSString *header = @"-----BEGIN CERTIFICATE-----\n"; NSString *footer = @"-----END CERTIFICATE-----\n"; @@ -102,8 +101,8 @@ } - (void)dealloc { - mbedtls_x509_crt_free(self.crt); - free(self.crt); + mbedtls_x509_crt_free(_crt); + free(_crt); } @end diff --git a/OpenVPN Adapter/OpenVPNPrivateKey.h b/OpenVPN Adapter/OpenVPNPrivateKey.h index 81ca5f6..61f8727 100644 --- a/OpenVPN Adapter/OpenVPNPrivateKey.h +++ b/OpenVPN Adapter/OpenVPNPrivateKey.h @@ -8,24 +8,24 @@ #import -#import "OpenVPNKeyType.h" +typedef NS_ENUM(NSInteger, OpenVPNKeyType); @interface OpenVPNPrivateKey : NSObject + (nullable OpenVPNPrivateKey *)keyWithPEM:(nonnull NSData *)pemData password:(nullable NSString *)password - error:(out NSError * __nullable * __nullable)error; + error:(out NSError * _Nullable * _Nullable)error; + (nullable OpenVPNPrivateKey *)keyWithDER:(nonnull NSData *)derData password:(nullable NSString *)password - error:(out NSError * __nullable * __nullable)error; + error:(out NSError * _Nullable * _Nullable)error; -- (nonnull instancetype) __unavailable init; +- (nonnull instancetype) init NS_UNAVAILABLE; @property (nonatomic, readonly) NSInteger size; @property (nonatomic, readonly) OpenVPNKeyType type; -- (nullable NSData *)pemData:(out NSError * __nullable * __nullable)error; -- (nullable NSData *)derData:(out NSError * __nullable * __nullable)error; +- (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 index deb4a6a..a941878 100644 --- a/OpenVPN Adapter/OpenVPNPrivateKey.m +++ b/OpenVPN Adapter/OpenVPNPrivateKey.m @@ -8,8 +8,9 @@ #import "OpenVPNPrivateKey.h" -#import +#include +#import "OpenVPNKeyType.h" #import "NSError+OpenVPNError.h" @interface OpenVPNPrivateKey () @@ -20,23 +21,6 @@ @implementation OpenVPNPrivateKey -- (instancetype)init { - self = [super init]; - if (self) { - self.ctx = malloc(sizeof(mbedtls_pk_context)); - mbedtls_pk_init(self.ctx); - } - return self; -} - -- (NSInteger)size { - return mbedtls_pk_get_bitlen(self.ctx); -} - -- (OpenVPNKeyType)type { - return (OpenVPNKeyType)mbedtls_pk_get_type(self.ctx); -} - + (nullable OpenVPNPrivateKey *)keyWithPEM:(NSData *)pemData password:(NSString *)password error:(out NSError **)error { OpenVPNPrivateKey *key = [OpenVPNPrivateKey new]; @@ -78,6 +62,22 @@ return key; } +- (instancetype)init { + if (self = [super init]) { + _ctx = malloc(sizeof(mbedtls_pk_context)); + mbedtls_pk_init(_ctx); + } + return self; +} + +- (NSInteger)size { + return mbedtls_pk_get_bitlen(self.ctx); +} + +- (OpenVPNKeyType)type { + return (OpenVPNKeyType)mbedtls_pk_get_type(self.ctx); +} + - (NSData *)pemData:(out NSError **)error { size_t buffer_length = mbedtls_pk_get_len(self.ctx) * 10; unsigned char *pem_buffer = malloc(buffer_length); @@ -123,8 +123,8 @@ } - (void)dealloc { - mbedtls_pk_free(self.ctx); - free(self.ctx); + mbedtls_pk_free(_ctx); + free(_ctx); } @end diff --git a/OpenVPN Adapter/OpenVPNReachability+Internal.h b/OpenVPN Adapter/OpenVPNReachability+Internal.h index d38837a..a13c3bd 100644 --- a/OpenVPN Adapter/OpenVPNReachability+Internal.h +++ b/OpenVPN Adapter/OpenVPNReachability+Internal.h @@ -6,7 +6,6 @@ // // -#import "OpenVPNReachabilityTracker.h" #import "OpenVPNReachability.h" @interface OpenVPNReachability (Internal) diff --git a/OpenVPN Adapter/OpenVPNReachability.h b/OpenVPN Adapter/OpenVPNReachability.h index 8ba4632..123982d 100644 --- a/OpenVPN Adapter/OpenVPNReachability.h +++ b/OpenVPN Adapter/OpenVPNReachability.h @@ -7,7 +7,8 @@ // #import -#import "OpenVPNReachabilityStatus.h" + +typedef NS_ENUM(NSInteger, OpenVPNReachabilityStatus); @interface OpenVPNReachability : NSObject diff --git a/OpenVPN Adapter/OpenVPNReachability.mm b/OpenVPN Adapter/OpenVPNReachability.mm index 360da7b..02d8383 100644 --- a/OpenVPN Adapter/OpenVPNReachability.mm +++ b/OpenVPN Adapter/OpenVPNReachability.mm @@ -6,11 +6,14 @@ // // -#import - #import "OpenVPNReachability.h" #import "OpenVPNReachability+Internal.h" +#include + +#import "OpenVPNReachabilityTracker.h" +#import "OpenVPNReachabilityStatus.h" + @interface OpenVPNReachability () { BOOL _isTracking; } @@ -45,13 +48,12 @@ } } -- (nonnull instancetype)init { - self = [super init]; - if (self) { +- (instancetype)init { + if (self = [super init]) { _isTracking = NO; - self.tracker = new OpenVPNReachabilityTracker(true, false, (__bridge void *)self); - self.reachability = new Reachability(true, true); + _tracker = new OpenVPNReachabilityTracker(true, false, (__bridge void *)self); + _reachability = new Reachability(true, true); } return self; } @@ -77,8 +79,8 @@ } - (void)dealloc { - delete self.tracker; - delete self.reachability; + delete _tracker; + delete _reachability; } @end diff --git a/OpenVPN Adapter/OpenVPNReachabilityTracker.h b/OpenVPN Adapter/OpenVPNReachabilityTracker.h index 6ac0982..da61403 100644 --- a/OpenVPN Adapter/OpenVPNReachabilityTracker.h +++ b/OpenVPN Adapter/OpenVPNReachabilityTracker.h @@ -6,7 +6,7 @@ // // -#import +#include using namespace openvpn; diff --git a/OpenVPN Adapter/OpenVPNReachabilityTracker.mm b/OpenVPN Adapter/OpenVPNReachabilityTracker.mm index a84cb38..68b4f2f 100644 --- a/OpenVPN Adapter/OpenVPNReachabilityTracker.mm +++ b/OpenVPN Adapter/OpenVPNReachabilityTracker.mm @@ -6,10 +6,13 @@ // // -#import "OpenVPNReachability+Internal.h" #import "OpenVPNReachabilityTracker.h" -OpenVPNReachabilityTracker::OpenVPNReachabilityTracker(const bool enable_internet, const bool enable_wifi, void* handler) : ReachabilityTracker(enable_internet, enable_wifi) { +#import "OpenVPNReachability+Internal.h" + +OpenVPNReachabilityTracker::OpenVPNReachabilityTracker(const bool enable_internet, const bool enable_wifi, void* handler) : + ReachabilityTracker(enable_internet, enable_wifi) +{ this->handler = handler; }