mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			92 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Matlab
		
	
		
		
			
		
	
	
			92 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Matlab
		
	
| 
											9 years ago
										 | // | ||
| 
											7 years ago
										 | //  Copyright (c) 2018 Open Whisper Systems. All rights reserved. | ||
| 
											9 years ago
										 | // | ||
| 
											9 years ago
										 | 
 | ||
|  | #import "OWSScrubbingLogFormatter.h" | ||
|  | 
 | ||
|  | NS_ASSUME_NONNULL_BEGIN | ||
|  | 
 | ||
|  | @implementation OWSScrubbingLogFormatter | ||
|  | 
 | ||
| 
											7 years ago
										 | - (NSRegularExpression *)phoneRegex | ||
|  | { | ||
| 
											7 years ago
										 |     static NSRegularExpression *regex = nil; | ||
|  |     static dispatch_once_t onceToken; | ||
|  |     dispatch_once(&onceToken, ^{ | ||
| 
											7 years ago
										 |         NSError *error; | ||
|  |         regex = [NSRegularExpression regularExpressionWithPattern:@"\\+\\d{7,12}(\\d{3})" | ||
|  |                                                           options:NSRegularExpressionCaseInsensitive | ||
|  |                                                             error:&error]; | ||
|  |         if (error || !regex) { | ||
| 
											7 years ago
										 |             OWSFail(@"could not compile regular expression: %@", error); | ||
| 
											7 years ago
										 |         } | ||
| 
											7 years ago
										 |     }); | ||
| 
											7 years ago
										 |     return regex; | ||
|  | } | ||
|  | 
 | ||
|  | - (NSRegularExpression *)dataRegex | ||
|  | { | ||
| 
											7 years ago
										 |     static NSRegularExpression *regex = nil; | ||
|  |     static dispatch_once_t onceToken; | ||
|  |     dispatch_once(&onceToken, ^{ | ||
| 
											7 years ago
										 |         NSError *error; | ||
|  |         regex = [NSRegularExpression regularExpressionWithPattern:@"<([\\da-f]{2})[\\da-f]{6}( [\\da-f]{8})*>" | ||
|  |                                                           options:NSRegularExpressionCaseInsensitive | ||
|  |                                                             error:&error]; | ||
|  |         if (error || !regex) { | ||
| 
											7 years ago
										 |             OWSFail(@"could not compile regular expression: %@", error); | ||
| 
											7 years ago
										 |         } | ||
| 
											7 years ago
										 |     }); | ||
| 
											7 years ago
										 |     return regex; | ||
|  | } | ||
|  | 
 | ||
| 
											7 years ago
										 | - (NSRegularExpression *)ipV4AddressRegex | ||
| 
											7 years ago
										 | { | ||
| 
											7 years ago
										 |     static NSRegularExpression *regex = nil; | ||
|  |     static dispatch_once_t onceToken; | ||
|  |     dispatch_once(&onceToken, ^{ | ||
| 
											7 years ago
										 |         // NOTE: The group matches the last quad of the IPv4 address. | ||
| 
											7 years ago
										 |         NSError *error; | ||
| 
											7 years ago
										 |         regex = [NSRegularExpression regularExpressionWithPattern:@"\\d+\\.\\d+\\.\\d+\\.(\\d+)" | ||
| 
											7 years ago
										 |                                                           options:NSRegularExpressionCaseInsensitive | ||
|  |                                                             error:&error]; | ||
|  |         if (error || !regex) { | ||
| 
											7 years ago
										 |             OWSFail(@"could not compile regular expression: %@", error); | ||
| 
											7 years ago
										 |         } | ||
| 
											7 years ago
										 |     }); | ||
| 
											7 years ago
										 |     return regex; | ||
|  | } | ||
|  | 
 | ||
| 
											8 years ago
										 | - (NSString *__nullable)formatLogMessage:(DDLogMessage *)logMessage | ||
| 
											9 years ago
										 | { | ||
| 
											8 years ago
										 |     NSString *logString = [super formatLogMessage:logMessage]; | ||
| 
											9 years ago
										 | 
 | ||
| 
											7 years ago
										 |     NSRegularExpression *phoneRegex = self.phoneRegex; | ||
| 
											8 years ago
										 |     logString = [phoneRegex stringByReplacingMatchesInString:logString | ||
|  |                                                      options:0 | ||
|  |                                                        range:NSMakeRange(0, [logString length]) | ||
|  |                                                 withTemplate:@"[ REDACTED_PHONE_NUMBER:xxx$1 ]"]; | ||
|  | 
 | ||
|  | 
 | ||
|  |     // We capture only the first two characters of the hex string for logging. | ||
| 
											8 years ago
										 |     // example log line: "Called someFunction with nsData: <01234567 89abcdef>" | ||
|  |     //  scrubbed output: "Called someFunction with nsData: [ REDACTED_DATA:01 ]" | ||
| 
											7 years ago
										 |     NSRegularExpression *dataRegex = self.dataRegex; | ||
| 
											8 years ago
										 |     logString = [dataRegex stringByReplacingMatchesInString:logString | ||
|  |                                                     options:0 | ||
|  |                                                       range:NSMakeRange(0, [logString length]) | ||
|  |                                                withTemplate:@"[ REDACTED_DATA:$1... ]"]; | ||
|  | 
 | ||
| 
											7 years ago
										 |     NSRegularExpression *ipV4AddressRegex = self.ipV4AddressRegex; | ||
|  |     logString = [ipV4AddressRegex stringByReplacingMatchesInString:logString | ||
|  |                                                            options:0 | ||
|  |                                                              range:NSMakeRange(0, [logString length]) | ||
|  |                                                       withTemplate:@"[ REDACTED_IPV4_ADDRESS:...$1 ]"]; | ||
| 
											7 years ago
										 | 
 | ||
| 
											8 years ago
										 |     return logString; | ||
| 
											9 years ago
										 | } | ||
|  | 
 | ||
|  | @end | ||
|  | 
 | ||
|  | NS_ASSUME_NONNULL_END |