mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-04-06 00:00:03 +08:00
Apply style guide rules to certificate, key and reachability classes
This commit is contained in:
@@ -11,14 +11,14 @@
|
|||||||
@interface OpenVPNCertificate : NSObject
|
@interface OpenVPNCertificate : NSObject
|
||||||
|
|
||||||
+ (nullable OpenVPNCertificate *)certificateWithPEM:(nonnull NSData *)pemData
|
+ (nullable OpenVPNCertificate *)certificateWithPEM:(nonnull NSData *)pemData
|
||||||
error:(out NSError * __nullable * __nullable)error;
|
error:(out NSError * _Nullable * _Nullable)error;
|
||||||
|
|
||||||
+ (nullable OpenVPNCertificate *)certificateWithDER:(nonnull NSData *)derData
|
+ (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 *)pemData:(out NSError * _Nullable * _Nullable)error;
|
||||||
- (nullable NSData *)derData:(out NSError * __nullable * __nullable)error;
|
- (nullable NSData *)derData:(out NSError * _Nullable * _Nullable)error;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
//
|
//
|
||||||
#import "OpenVPNCertificate.h"
|
#import "OpenVPNCertificate.h"
|
||||||
|
|
||||||
#import <mbedtls/x509_crt.h>
|
#include <mbedtls/x509_crt.h>
|
||||||
#import <mbedtls/pem.h>
|
#include <mbedtls/pem.h>
|
||||||
|
|
||||||
#import "NSError+OpenVPNError.h"
|
#import "NSError+OpenVPNError.h"
|
||||||
|
|
||||||
@@ -20,16 +20,6 @@
|
|||||||
|
|
||||||
@implementation OpenVPNCertificate
|
@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 *)certificateWithPEM:(NSData *)pemData error:(out NSError **)error {
|
||||||
OpenVPNCertificate *certificate = [OpenVPNCertificate new];
|
OpenVPNCertificate *certificate = [OpenVPNCertificate new];
|
||||||
|
|
||||||
@@ -62,6 +52,15 @@
|
|||||||
return certificate;
|
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 {
|
- (NSData *)pemData:(out NSError **)error {
|
||||||
NSString *header = @"-----BEGIN CERTIFICATE-----\n";
|
NSString *header = @"-----BEGIN CERTIFICATE-----\n";
|
||||||
NSString *footer = @"-----END CERTIFICATE-----\n";
|
NSString *footer = @"-----END CERTIFICATE-----\n";
|
||||||
@@ -102,8 +101,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
mbedtls_x509_crt_free(self.crt);
|
mbedtls_x509_crt_free(_crt);
|
||||||
free(self.crt);
|
free(_crt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -8,24 +8,24 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
#import "OpenVPNKeyType.h"
|
typedef NS_ENUM(NSInteger, OpenVPNKeyType);
|
||||||
|
|
||||||
@interface OpenVPNPrivateKey : NSObject
|
@interface OpenVPNPrivateKey : NSObject
|
||||||
|
|
||||||
+ (nullable OpenVPNPrivateKey *)keyWithPEM:(nonnull NSData *)pemData
|
+ (nullable OpenVPNPrivateKey *)keyWithPEM:(nonnull NSData *)pemData
|
||||||
password:(nullable NSString *)password
|
password:(nullable NSString *)password
|
||||||
error:(out NSError * __nullable * __nullable)error;
|
error:(out NSError * _Nullable * _Nullable)error;
|
||||||
|
|
||||||
+ (nullable OpenVPNPrivateKey *)keyWithDER:(nonnull NSData *)derData
|
+ (nullable OpenVPNPrivateKey *)keyWithDER:(nonnull NSData *)derData
|
||||||
password:(nullable NSString *)password
|
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) NSInteger size;
|
||||||
@property (nonatomic, readonly) OpenVPNKeyType type;
|
@property (nonatomic, readonly) OpenVPNKeyType type;
|
||||||
|
|
||||||
- (nullable NSData *)pemData:(out NSError * __nullable * __nullable)error;
|
- (nullable NSData *)pemData:(out NSError * _Nullable * _Nullable)error;
|
||||||
- (nullable NSData *)derData:(out NSError * __nullable * __nullable)error;
|
- (nullable NSData *)derData:(out NSError * _Nullable * _Nullable)error;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -8,8 +8,9 @@
|
|||||||
|
|
||||||
#import "OpenVPNPrivateKey.h"
|
#import "OpenVPNPrivateKey.h"
|
||||||
|
|
||||||
#import <mbedtls/pk.h>
|
#include <mbedtls/pk.h>
|
||||||
|
|
||||||
|
#import "OpenVPNKeyType.h"
|
||||||
#import "NSError+OpenVPNError.h"
|
#import "NSError+OpenVPNError.h"
|
||||||
|
|
||||||
@interface OpenVPNPrivateKey ()
|
@interface OpenVPNPrivateKey ()
|
||||||
@@ -20,23 +21,6 @@
|
|||||||
|
|
||||||
@implementation OpenVPNPrivateKey
|
@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 {
|
+ (nullable OpenVPNPrivateKey *)keyWithPEM:(NSData *)pemData password:(NSString *)password error:(out NSError **)error {
|
||||||
OpenVPNPrivateKey *key = [OpenVPNPrivateKey new];
|
OpenVPNPrivateKey *key = [OpenVPNPrivateKey new];
|
||||||
|
|
||||||
@@ -78,6 +62,22 @@
|
|||||||
return key;
|
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 {
|
- (NSData *)pemData:(out NSError **)error {
|
||||||
size_t buffer_length = mbedtls_pk_get_len(self.ctx) * 10;
|
size_t buffer_length = mbedtls_pk_get_len(self.ctx) * 10;
|
||||||
unsigned char *pem_buffer = malloc(buffer_length);
|
unsigned char *pem_buffer = malloc(buffer_length);
|
||||||
@@ -123,8 +123,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
mbedtls_pk_free(self.ctx);
|
mbedtls_pk_free(_ctx);
|
||||||
free(self.ctx);
|
free(_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "OpenVPNReachabilityTracker.h"
|
|
||||||
#import "OpenVPNReachability.h"
|
#import "OpenVPNReachability.h"
|
||||||
|
|
||||||
@interface OpenVPNReachability (Internal)
|
@interface OpenVPNReachability (Internal)
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "OpenVPNReachabilityStatus.h"
|
|
||||||
|
typedef NS_ENUM(NSInteger, OpenVPNReachabilityStatus);
|
||||||
|
|
||||||
@interface OpenVPNReachability : NSObject
|
@interface OpenVPNReachability : NSObject
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,14 @@
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <openvpn/apple/reachable.hpp>
|
|
||||||
|
|
||||||
#import "OpenVPNReachability.h"
|
#import "OpenVPNReachability.h"
|
||||||
#import "OpenVPNReachability+Internal.h"
|
#import "OpenVPNReachability+Internal.h"
|
||||||
|
|
||||||
|
#include <openvpn/apple/reachable.hpp>
|
||||||
|
|
||||||
|
#import "OpenVPNReachabilityTracker.h"
|
||||||
|
#import "OpenVPNReachabilityStatus.h"
|
||||||
|
|
||||||
@interface OpenVPNReachability () {
|
@interface OpenVPNReachability () {
|
||||||
BOOL _isTracking;
|
BOOL _isTracking;
|
||||||
}
|
}
|
||||||
@@ -45,13 +48,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (nonnull instancetype)init {
|
- (instancetype)init {
|
||||||
self = [super init];
|
if (self = [super init]) {
|
||||||
if (self) {
|
|
||||||
_isTracking = NO;
|
_isTracking = NO;
|
||||||
|
|
||||||
self.tracker = new OpenVPNReachabilityTracker(true, false, (__bridge void *)self);
|
_tracker = new OpenVPNReachabilityTracker(true, false, (__bridge void *)self);
|
||||||
self.reachability = new Reachability(true, true);
|
_reachability = new Reachability(true, true);
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -77,8 +79,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
delete self.tracker;
|
delete _tracker;
|
||||||
delete self.reachability;
|
delete _reachability;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <openvpn/apple/reachable.hpp>
|
#include <openvpn/apple/reachable.hpp>
|
||||||
|
|
||||||
using namespace openvpn;
|
using namespace openvpn;
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,13 @@
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "OpenVPNReachability+Internal.h"
|
|
||||||
#import "OpenVPNReachabilityTracker.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;
|
this->handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user