mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2024-10-06 09:12:08 +08:00
Merge branch 'develop' into feature/documentation
* develop: Update method signatures that have error objects
This commit is contained in:
commit
f3381f898d
@ -47,7 +47,7 @@
|
||||
|
||||
#pragma mark - OpenVPNClient Lifecycle
|
||||
|
||||
- (OpenVPNProperties *)applyConfiguration:(OpenVPNConfiguration *)configuration error:(NSError * _Nullable __autoreleasing *)error {
|
||||
- (OpenVPNProperties *)applyConfiguration:(OpenVPNConfiguration *)configuration error:(NSError * __autoreleasing *)error {
|
||||
ClientAPI::EvalConfig eval = self.vpnClient->eval_config(configuration.config);
|
||||
|
||||
if (eval.error) {
|
||||
@ -65,7 +65,7 @@
|
||||
return [[OpenVPNProperties alloc] initWithEvalConfig:eval];
|
||||
}
|
||||
|
||||
- (BOOL)provideCredentials:(OpenVPNCredentials *)credentials error:(NSError * _Nullable __autoreleasing *)error {
|
||||
- (BOOL)provideCredentials:(OpenVPNCredentials *)credentials error:(NSError * __autoreleasing *)error {
|
||||
ClientAPI::Status status = self.vpnClient->provide_creds(credentials.credentials);
|
||||
|
||||
if (status.error) {
|
||||
|
@ -8,17 +8,18 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OpenVPNCertificate : NSObject
|
||||
|
||||
+ (nullable OpenVPNCertificate *)certificateWithPEM:(nonnull NSData *)pemData
|
||||
error:(out NSError * _Nullable * _Nullable)error;
|
||||
+ (nullable OpenVPNCertificate *)certificateWithPEM:(NSData *)pemData error:(NSError **)error;
|
||||
+ (nullable OpenVPNCertificate *)certificateWithDER:(NSData *)derData error:(NSError **)error;
|
||||
|
||||
+ (nullable OpenVPNCertificate *)certificateWithDER:(nonnull NSData *)derData
|
||||
error:(out NSError * _Nullable * _Nullable)error;
|
||||
- (instancetype) init NS_UNAVAILABLE;
|
||||
|
||||
- (nonnull instancetype) init NS_UNAVAILABLE;
|
||||
|
||||
- (nullable NSData *)pemData:(out NSError * _Nullable * _Nullable)error;
|
||||
- (nullable NSData *)derData:(out NSError * _Nullable * _Nullable)error;
|
||||
- (nullable NSData *)pemData:(NSError **)error;
|
||||
- (nullable NSData *)derData:(NSError **)error;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
@implementation OpenVPNCertificate
|
||||
|
||||
+ (OpenVPNCertificate *)certificateWithPEM:(NSData *)pemData error:(out NSError **)error {
|
||||
+ (OpenVPNCertificate *)certificateWithPEM:(NSData *)pemData error:(NSError * __autoreleasing *)error {
|
||||
OpenVPNCertificate *certificate = [OpenVPNCertificate new];
|
||||
|
||||
NSString *pemString = [[NSString alloc] initWithData:pemData encoding:NSUTF8StringEncoding];
|
||||
@ -37,7 +37,7 @@
|
||||
return certificate;
|
||||
}
|
||||
|
||||
+ (OpenVPNCertificate *)certificateWithDER:(NSData *)derData error:(out NSError **)error {
|
||||
+ (OpenVPNCertificate *)certificateWithDER:(NSData *)derData error:(NSError * __autoreleasing *)error {
|
||||
OpenVPNCertificate *certificate = [OpenVPNCertificate new];
|
||||
|
||||
int result = mbedtls_x509_crt_parse_der(certificate.crt, derData.bytes, derData.length);
|
||||
@ -61,7 +61,7 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSData *)pemData:(out NSError **)error {
|
||||
- (NSData *)pemData:(NSError * __autoreleasing *)error {
|
||||
NSString *header = @"-----BEGIN CERTIFICATE-----\n";
|
||||
NSString *footer = @"-----END CERTIFICATE-----\n";
|
||||
|
||||
@ -87,7 +87,7 @@
|
||||
return pemData;
|
||||
}
|
||||
|
||||
- (NSData *)derData:(out NSError **)error {
|
||||
- (NSData *)derData:(NSError * __autoreleasing *)error {
|
||||
if (self.crt->raw.p == NULL || self.crt->raw.len == 0) {
|
||||
if (error) {
|
||||
*error = [NSError ovpn_errorObjectForMbedTLSError:MBEDTLS_ERR_X509_BAD_INPUT_DATA
|
||||
|
@ -41,7 +41,7 @@ static void SocketCallback(CFSocketRef socket, CFSocketCallBackType type, CFData
|
||||
[bridge writePackets:@[packet] toPacketFlow:bridge.packetFlow];
|
||||
}
|
||||
|
||||
- (BOOL)configureSocketsWithError:(NSError **)error {
|
||||
- (BOOL)configureSocketsWithError:(NSError * __autoreleasing *)error {
|
||||
int sockets[2];
|
||||
if (socketpair(PF_LOCAL, SOCK_DGRAM, IPPROTO_IP, sockets) == -1) {
|
||||
if (error) {
|
||||
@ -90,7 +90,7 @@ static void SocketCallback(CFSocketRef socket, CFSocketCallBackType type, CFData
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)configureOptionsForSocket:(CFSocketRef)socket error:(NSError **)error {
|
||||
- (BOOL)configureOptionsForSocket:(CFSocketRef)socket error:(NSError * __autoreleasing *)error {
|
||||
CFSocketNativeHandle socketHandle = CFSocketGetNative(socket);
|
||||
|
||||
int buf_value = 65536;
|
||||
|
@ -10,22 +10,26 @@
|
||||
|
||||
typedef NS_ENUM(NSInteger, OpenVPNKeyType);
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OpenVPNPrivateKey : NSObject
|
||||
|
||||
+ (nullable OpenVPNPrivateKey *)keyWithPEM:(nonnull NSData *)pemData
|
||||
+ (nullable OpenVPNPrivateKey *)keyWithPEM:(NSData *)pemData
|
||||
password:(nullable NSString *)password
|
||||
error:(out NSError * _Nullable * _Nullable)error;
|
||||
error:(NSError **)error;
|
||||
|
||||
+ (nullable OpenVPNPrivateKey *)keyWithDER:(nonnull NSData *)derData
|
||||
+ (nullable OpenVPNPrivateKey *)keyWithDER:(NSData *)derData
|
||||
password:(nullable NSString *)password
|
||||
error:(out NSError * _Nullable * _Nullable)error;
|
||||
error:(NSError **)error;
|
||||
|
||||
- (nonnull instancetype) init NS_UNAVAILABLE;
|
||||
- (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:(NSError **)error;
|
||||
- (nullable NSData *)derData:(NSError **)error;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
@implementation OpenVPNPrivateKey
|
||||
|
||||
+ (nullable OpenVPNPrivateKey *)keyWithPEM:(NSData *)pemData password:(NSString *)password error:(out NSError **)error {
|
||||
+ (OpenVPNPrivateKey *)keyWithPEM:(NSData *)pemData password:(NSString *)password error:(NSError * __autoreleasing *)error {
|
||||
OpenVPNPrivateKey *key = [OpenVPNPrivateKey new];
|
||||
|
||||
NSString *pemString = [[NSString alloc] initWithData:pemData encoding:NSUTF8StringEncoding];
|
||||
@ -43,7 +43,7 @@
|
||||
return key;
|
||||
}
|
||||
|
||||
+ (nullable OpenVPNPrivateKey *)keyWithDER:(NSData *)derData password:(NSString *)password error:(out NSError **)error {
|
||||
+ (OpenVPNPrivateKey *)keyWithDER:(NSData *)derData password:(NSString *)password error:(NSError * __autoreleasing *)error {
|
||||
OpenVPNPrivateKey *key = [OpenVPNPrivateKey new];
|
||||
|
||||
size_t password_length = password != nil ? strlen(password.UTF8String) : 0;
|
||||
@ -78,7 +78,7 @@
|
||||
return (OpenVPNKeyType)mbedtls_pk_get_type(self.ctx);
|
||||
}
|
||||
|
||||
- (NSData *)pemData:(out NSError **)error {
|
||||
- (NSData *)pemData:(NSError * __autoreleasing *)error {
|
||||
size_t buffer_length = mbedtls_pk_get_len(self.ctx) * 10;
|
||||
unsigned char *pem_buffer = malloc(buffer_length);
|
||||
|
||||
@ -99,7 +99,7 @@
|
||||
return pemData;
|
||||
}
|
||||
|
||||
- (NSData *)derData:(out NSError **)error {
|
||||
- (NSData *)derData:(NSError * __autoreleasing *)error {
|
||||
size_t buffer_length = mbedtls_pk_get_len(self.ctx) * 10;
|
||||
unsigned char *der_buffer = malloc(buffer_length);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user