-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e1f404
commit 7faa1cf
Showing
11 changed files
with
276 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
xcconf/Sources/CodeGen/XCCParametersCodeGeneratorProtocol.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// XCCParametersCodeGeneratorProtocol.h | ||
// xcconf | ||
// | ||
// Created by AlexDenisov on 22/06/15. | ||
// Copyright (c) 2015 AlexDenisov. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@class XCCEnvironment; | ||
|
||
@protocol XCCParametersCodeGeneratorProtocol <NSObject> | ||
|
||
- (instancetype)initWithEnvironment:(XCCEnvironment *)environment; | ||
- (NSString *)generateCode; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// XCCSecureParametersCodeGenerator.h | ||
// xcconf | ||
// | ||
// Created by AlexDenisov on 22/06/15. | ||
// Copyright (c) 2015 AlexDenisov. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "XCCParametersCodeGeneratorProtocol.h" | ||
|
||
@interface XCCSecureParametersCodeGenerator : NSObject | ||
<XCCParametersCodeGeneratorProtocol> | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// XCCSecureParametersCodeGenerator.m | ||
// xcconf | ||
// | ||
// Created by AlexDenisov on 22/06/15. | ||
// Copyright (c) 2015 AlexDenisov. All rights reserved. | ||
// | ||
|
||
#import "XCCSecureParametersCodeGenerator.h" | ||
#import "XCCEnvironment.h" | ||
|
||
@interface XCCSecureParametersCodeGenerator () | ||
|
||
@property (strong) XCCEnvironment *environment; | ||
|
||
@end | ||
|
||
@implementation XCCSecureParametersCodeGenerator | ||
|
||
- (instancetype)initWithEnvironment:(XCCEnvironment *)environment { | ||
self = [super init]; | ||
|
||
self.environment = environment; | ||
|
||
return self; | ||
} | ||
|
||
- (NSString *)generateCode { | ||
NSDictionary *parameters = self.environment.parameters; | ||
NSMutableArray *codeChunks = [NSMutableArray new]; | ||
|
||
if (self.environment.name) { | ||
NSString *environment = [self codeForValue:self.environment.name withKey:@"environment"]; | ||
[codeChunks addObject:environment]; | ||
} | ||
|
||
for (NSString *key in parameters.allKeys) { | ||
NSString *chunk = [self codeForValue:parameters[key] withKey:key]; | ||
[codeChunks addObject:chunk]; | ||
} | ||
return [codeChunks componentsJoinedByString:@"\n"]; | ||
} | ||
|
||
- (NSString *)codeForValue:(NSString *)value withKey:(NSString *)key { | ||
NSString *format = @"- (NSString *)%@ { %@ }"; | ||
NSString *encryptedBody = [self encryptBody:value]; | ||
NSString *method = [NSString stringWithFormat:format, key, encryptedBody]; | ||
return method; | ||
} | ||
|
||
- (NSString *)encryptBody:(NSString *)value { | ||
const char *rawValue = value.UTF8String; | ||
const unsigned long valueLength = strlen(rawValue); | ||
|
||
NSMutableString *encryptedValue = [NSMutableString new]; | ||
for (unsigned long i = 0; i < valueLength; i++) { | ||
NSString *encryptedCharacter = [NSString stringWithFormat:@"s[%lu] = '%c'; ", i, rawValue[i]]; | ||
[encryptedValue appendString:encryptedCharacter]; | ||
} | ||
NSString *encryptedCharacter = [NSString stringWithFormat:@"s[%lu] = 0x00; ", valueLength]; | ||
[encryptedValue appendString:encryptedCharacter]; | ||
|
||
return [NSString stringWithFormat:@"char s[%lu]; %@return @(s);", valueLength + 1, encryptedValue]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.