mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2024-10-06 09:12:08 +08:00
Apply style guide rules to certificate, key and reachability classes
This commit is contained in:
parent
eff0bccfef
commit
7078de3bae
@ -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
|
||||
|
@ -7,8 +7,8 @@
|
||||
//
|
||||
#import "OpenVPNCertificate.h"
|
||||
|
||||
#import <mbedtls/x509_crt.h>
|
||||
#import <mbedtls/pem.h>
|
||||
#include <mbedtls/x509_crt.h>
|
||||
#include <mbedtls/pem.h>
|
||||
|
||||
#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
|
||||
|
@ -8,24 +8,24 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#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
|
||||
|
@ -8,8 +8,9 @@
|
||||
|
||||
#import "OpenVPNPrivateKey.h"
|
||||
|
||||
#import <mbedtls/pk.h>
|
||||
#include <mbedtls/pk.h>
|
||||
|
||||
#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
|
||||
|
@ -6,7 +6,6 @@
|
||||
//
|
||||
//
|
||||
|
||||
#import "OpenVPNReachabilityTracker.h"
|
||||
#import "OpenVPNReachability.h"
|
||||
|
||||
@interface OpenVPNReachability (Internal)
|
||||
|
@ -7,7 +7,8 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "OpenVPNReachabilityStatus.h"
|
||||
|
||||
typedef NS_ENUM(NSInteger, OpenVPNReachabilityStatus);
|
||||
|
||||
@interface OpenVPNReachability : NSObject
|
||||
|
||||
|
@ -6,11 +6,14 @@
|
||||
//
|
||||
//
|
||||
|
||||
#import <openvpn/apple/reachable.hpp>
|
||||
|
||||
#import "OpenVPNReachability.h"
|
||||
#import "OpenVPNReachability+Internal.h"
|
||||
|
||||
#include <openvpn/apple/reachable.hpp>
|
||||
|
||||
#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
|
||||
|
@ -6,7 +6,7 @@
|
||||
//
|
||||
//
|
||||
|
||||
#import <openvpn/apple/reachable.hpp>
|
||||
#include <openvpn/apple/reachable.hpp>
|
||||
|
||||
using namespace openvpn;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user