Skip to content

Commit

Permalink
Update CDVCryptURLProtocol.m
Browse files Browse the repository at this point in the history
More updates from PeterHDD code PeterHdd#2
  • Loading branch information
givethanks1 authored Jun 2, 2021
1 parent 6d9ef9f commit f32c501
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/ios/CDVCryptURLProtocol.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ - (void)startLoading

NSURL *urls = [[NSURL alloc] initWithString:finalUrl];
url = urls;

// if ([[self class] checkCryptFile:url]) {
NSString *mimeType = [self getMimeType:url];
//if ([[self class] checkCryptFile:url]) {
NSString *mimeType = [self getMimeType:url];

NSError* error;
NSString* content = [[NSString alloc] initWithContentsOfFile:url.path encoding:NSUTF8StringEncoding error:&error];
if (!error) {
NSLog(@"Decrypt: %@",url);
NSData* data = [self decryptAES256WithKey:kCryptKey iv:kCryptIv data:content];
NSData* data = [self decryptAES256WithKey:kCryptKey iv:kCryptIv data:content];
[self sendResponseWithResponseCode:200 data:data mimeType:mimeType];
} else {
NSLog(@"The error while loading: %@",error);
}
NSLog(@"The error while loading: %@",error);
}
//}

[super startLoading];
Expand All @@ -83,7 +83,6 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon
self.mutableData = [[NSMutableData alloc] init];
}


- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[self.client URLProtocol:self didLoadData:data];
[self.mutableData appendData:data];
Expand Down Expand Up @@ -222,6 +221,7 @@ - (NSString*)getMimeTypeFromPath:(NSString*)fullPath

- (void)sendResponseWithResponseCode:(NSInteger)statusCode data:(NSData*)data mimeType:(NSString*)mimeType
{
NSLog(@"inside response");
if (mimeType == nil) {
mimeType = @"text/plain";
}
Expand All @@ -235,4 +235,10 @@ - (void)sendResponseWithResponseCode:(NSInteger)statusCode data:(NSData*)data mi
[[self client] URLProtocolDidFinishLoading:self];
}

+ (NSURLRequest*)canonicalRequestForRequest:(NSURLRequest*)request
{
NSLog(@"%@ received %@", self, NSStringFromSelector(_cmd));
return request;
}

@end

0 comments on commit f32c501

Please sign in to comment.