From 949364fa0ba4f46c22d97096fa8654dd1821d0d4 Mon Sep 17 00:00:00 2001 From: hansemannn Date: Wed, 15 Aug 2018 11:35:06 +0200 Subject: [PATCH 1/5] chore: cleanup project, resolve compiler warnings --- ios/Classes/TiCryptoCryptorProxy.h | 2 +- ios/Classes/TiCryptoCryptorProxy.m | 2 +- ios/Classes/TiCryptoModule.h | 11 +- ios/Classes/TiCryptoModule.m | 20 +-- ios/Classes/TiCryptoUtils.h | 2 +- ios/Classes/TiCryptoUtils.m | 4 +- ios/README | 151 ------------------ ios/assets/README | 6 - .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../UserInterfaceState.xcuserstate | Bin 0 -> 23523 bytes .../xcschemes/xcschememanagement.plist | 19 +++ ios/example/app.js | 6 +- ios/hooks/README | 1 - ios/hooks/add.py | 35 ---- ios/hooks/install.py | 19 --- ios/hooks/remove.py | 34 ---- ios/hooks/uninstall.py | 18 --- ios/manifest | 7 +- ios/platform/README | 3 - ios/titanium.xcconfig | 2 +- 21 files changed, 63 insertions(+), 294 deletions(-) delete mode 100644 ios/README delete mode 100644 ios/assets/README create mode 100644 ios/crypto.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 ios/crypto.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 ios/crypto.xcodeproj/project.xcworkspace/xcuserdata/hknoechel.xcuserdatad/UserInterfaceState.xcuserstate create mode 100644 ios/crypto.xcodeproj/xcuserdata/hknoechel.xcuserdatad/xcschemes/xcschememanagement.plist delete mode 100644 ios/hooks/README delete mode 100644 ios/hooks/add.py delete mode 100644 ios/hooks/install.py delete mode 100644 ios/hooks/remove.py delete mode 100644 ios/hooks/uninstall.py delete mode 100644 ios/platform/README diff --git a/ios/Classes/TiCryptoCryptorProxy.h b/ios/Classes/TiCryptoCryptorProxy.h index b0f1932..28cb85e 100644 --- a/ios/Classes/TiCryptoCryptorProxy.h +++ b/ios/Classes/TiCryptoCryptorProxy.h @@ -1,6 +1,6 @@ /** * Ti.Crypto Module - * Copyright (c) 2010-2013 by Appcelerator, Inc. All Rights Reserved. + * Copyright (c) 2010-present by Appcelerator, Inc. All Rights Reserved. * Please see the LICENSE included with this distribution for details. */ diff --git a/ios/Classes/TiCryptoCryptorProxy.m b/ios/Classes/TiCryptoCryptorProxy.m index c9bb59c..873fe7c 100644 --- a/ios/Classes/TiCryptoCryptorProxy.m +++ b/ios/Classes/TiCryptoCryptorProxy.m @@ -1,6 +1,6 @@ /** * Ti.Crypto Module - * Copyright (c) 2010-2013 by Appcelerator, Inc. All Rights Reserved. + * Copyright (c) 2010-present by Appcelerator, Inc. All Rights Reserved. * Please see the LICENSE included with this distribution for details. */ diff --git a/ios/Classes/TiCryptoModule.h b/ios/Classes/TiCryptoModule.h index 5e5963e..486f1aa 100644 --- a/ios/Classes/TiCryptoModule.h +++ b/ios/Classes/TiCryptoModule.h @@ -1,6 +1,6 @@ /** * Ti.Crypto Module - * Copyright (c) 2010-2013 by Appcelerator, Inc. All Rights Reserved. + * Copyright (c) 2010-present by Appcelerator, Inc. All Rights Reserved. * Please see the LICENSE included with this distribution for details. */ @@ -21,8 +21,11 @@ extern NSString * const kDataTypeBlobName; extern NSString * const kDataTypeHexStringName; extern NSString * const kDataTypeBase64StringName; -@interface TiCryptoModule : TiModule -{ -} +@interface TiCryptoModule : TiModule + + +-(NSString*)decodeData:(id)args; + +-(NSNumber*)encodeData:(id)args; @end diff --git a/ios/Classes/TiCryptoModule.m b/ios/Classes/TiCryptoModule.m index da5308a..f61f55f 100644 --- a/ios/Classes/TiCryptoModule.m +++ b/ios/Classes/TiCryptoModule.m @@ -1,6 +1,6 @@ /** * Ti.Crypto Module - * Copyright (c) 2010-2013 by Appcelerator, Inc. All Rights Reserved. + * Copyright (c) 2010-present by Appcelerator, Inc. All Rights Reserved. * Please see the LICENSE included with this distribution for details. */ @@ -77,9 +77,9 @@ +(cryptoDataType)constantToDataType:(NSString*)type { if (dataTypeMap == nil) { dataTypeMap = [[NSDictionary alloc] initWithObjectsAndKeys: - NUMINT(kDataTypeBlob),kDataTypeBlobName, - NUMINT(kDataTypeHexString),kDataTypeHexStringName, - NUMINT(kDataTypeBase64String),kDataTypeBase64StringName, + @(kDataTypeBlob),kDataTypeBlobName, + @(kDataTypeHexString),kDataTypeHexStringName, + @(kDataTypeBase64String),kDataTypeBase64StringName, nil]; } return [[dataTypeMap valueForKey:type] intValue]; @@ -152,18 +152,18 @@ -(NSNumber*)encodeData:(id)args } // Verify that the offset is within range - int destLength = [[dest data] length]; + NSUInteger destLength = [[dest data] length]; if (destPosition >= destLength) { NSLog(@"[ERROR] Destination position of %d is past end of buffer. Buffer size is %d.", destPosition, destLength); - return NUMINT(BAD_DEST_OFFSET); + return @(BAD_DEST_OFFSET); } // Verify that the destination can hold the result - int srcLength = [data length]; - int neededLength = destPosition + srcLength; + NSUInteger srcLength = [data length]; + NSUInteger neededLength = destPosition + srcLength; if (neededLength > destLength) { NSLog(@"[ERROR] Destination buffer size of %d is too small. Needed %d.", destLength, neededLength); - return NUMINT(TOO_SMALL); + return @(TOO_SMALL); } void* bufferBytes = [[dest data] mutableBytes]; @@ -171,7 +171,7 @@ -(NSNumber*)encodeData:(id)args memcpy(bufferBytes + destPosition, srcBytes, srcLength); - return NUMINT(destPosition + srcLength); + return @(destPosition + srcLength); } #pragma mark Constants diff --git a/ios/Classes/TiCryptoUtils.h b/ios/Classes/TiCryptoUtils.h index f0d7d0d..f7f064e 100644 --- a/ios/Classes/TiCryptoUtils.h +++ b/ios/Classes/TiCryptoUtils.h @@ -1,6 +1,6 @@ /** * Ti.Crypto Module - * Copyright (c) 2010-2013 by Appcelerator, Inc. All Rights Reserved. + * Copyright (c) 2010-present by Appcelerator, Inc. All Rights Reserved. * Please see the LICENSE included with this distribution for details. */ diff --git a/ios/Classes/TiCryptoUtils.m b/ios/Classes/TiCryptoUtils.m index 2044d14..60bb932 100644 --- a/ios/Classes/TiCryptoUtils.m +++ b/ios/Classes/TiCryptoUtils.m @@ -1,6 +1,6 @@ /** * Ti.Crypto Module - * Copyright (c) 2010-2013 by Appcelerator, Inc. All Rights Reserved. + * Copyright (c) 2010-present by Appcelerator, Inc. All Rights Reserved. * Please see the LICENSE included with this distribution for details. */ @@ -36,7 +36,7 @@ +(NSMutableData*)convertFromHex:(NSString*)value char byte_chars[3]; byte_chars[2] = '\0'; int i; - int len = [valueToConvert length] / 2; + NSUInteger len = [valueToConvert length] / 2; for (i=0; i < len; i++) { byte_chars[0] = [valueToConvert characterAtIndex:i*2]; byte_chars[1] = [valueToConvert characterAtIndex:i*2+1]; diff --git a/ios/README b/ios/README deleted file mode 100644 index c039b70..0000000 --- a/ios/README +++ /dev/null @@ -1,151 +0,0 @@ -Appcelerator Titanium iPhone Module Project -=========================================== - -This is a skeleton Titanium Mobile iPhone module project. Modules can be -used to extend the functionality of Titanium by providing additional native -code that is compiled into your application at build time and can expose certain -APIs into JavaScript. - -MODULE NAMING --------------- - -Choose a unique module id for your module. This ID usually follows a namespace -convention using DNS notation. For example, com.appcelerator.module.test. This -ID can only be used once by all public modules in Titanium. - - -COMPONENTS ------------ - -Components that are exposed by your module must follow a special naming convention. -A component (widget, proxy, etc) must be named with the pattern: - - TiProxy - -For example, if you component was called Foo, your proxy would be named: - - TiMyfirstFooProxy - -For view proxies or widgets, you must create both a view proxy and a view implementation. -If you widget was named proxy, you would create the following files: - - TiMyfirstFooProxy.h - TiMyfirstFooProxy.m - TiMyfirstFoo.h - TiMyfirstFoo.m - -The view implementation is named the same except it does contain the suffix `Proxy`. - -View implementations extend the Titanium base class `TiUIView`. View Proxies extend the -Titanium base class `TiUIViewProxy` or `TiUIWidgetProxy`. - -For proxies that are simply native objects that can be returned to JavaScript, you can -simply extend `TiProxy` and no view implementation is required. - - -GET STARTED ------------- - -1. Edit manifest with the appropriate details about your module. -2. Edit LICENSE to add your license details. -3. Place any assets (such as PNG files) that are required in the assets folder. -4. Edit the titanium.xcconfig and make sure you're building for the right Titanium version. -5. Code and build. - -BUILD TIME COMPILER CONFIG --------------------------- - -You can edit the file `module.xcconfig` to include any build time settings that should be -set during application compilation that your module requires. This file will automatically get `#include` in the main application project. - -For more information about this file, please see the Apple documentation at: - - - - -DOCUMENTATION FOR YOUR MODULE ------------------------------ - -You should provide at least minimal documentation for your module in `documentation` folder using the Markdown syntax. - -For more information on the Markdown syntax, refer to this documentation at: - - - - -TEST HARNESS EXAMPLE FOR YOUR MODULE ------------------------------------- - -The `example` directory contains a skeleton application test harness that can be -used for testing and providing an example of usage to the users of your module. - - -INSTALL YOUR MODULE --------------------- - -1. Run `build.py` which creates your distribution -2. cd to `/Library/Application Support/Titanium` -3. copy this zip file into the folder of your Titanium SDK - -REGISTER YOUR MODULE ---------------------- - -Register your module with your application by editing `tiapp.xml` and adding your module. -Example: - - - ti.crypto - - -When you run your project, the compiler will know automatically compile in your module -dependencies and copy appropriate image assets into the application. - -USING YOUR MODULE IN CODE -------------------------- - -To use your module in code, you will need to require it. - -For example, - - var my_module = require('ti.crypto'); - my_module.foo(); - -WRITING PURE JS NATIVE MODULES ------------------------------- - -You can write a pure JavaScript "natively compiled" module. This is nice if you -want to distribute a JS module pre-compiled. - -To create a module, create a file named ti.crypto.js under the assets folder. -This file must be in the Common JS format. For example: - - exports.echo = function(s) - { - return s; - }; - -Any functions and properties that are exported will be made available as part of your -module. All other code inside your JS will be private to your module. - -For pure JS module, you don't need to modify any of the Objective-C module code. You -can leave it as-is and build. - -TESTING YOUR MODULE -------------------- - -Run the `titanium.py` script to test your module or test from within XCode. -To test with the script, execute: - - titanium run --dir=YOURMODULEDIR - - -This will execute the app.js in the example folder as a Titanium application. - - -DISTRIBUTING YOUR MODULE -------------------------- - -Currently, you will need to manually distribution your module distribution zip file directly. However, in the near future, we will make module distribution and sharing built-in to Titanium Developer and in the Titanium Marketplace! - - -Cheers! diff --git a/ios/assets/README b/ios/assets/README deleted file mode 100644 index 71d6f04..0000000 --- a/ios/assets/README +++ /dev/null @@ -1,6 +0,0 @@ -Place your assets like PNG files in this directory and they will be packaged with your module. - -If you create a file named ti.crypto.js in this directory, it will be -compiled and used as your module. This allows you to run pure Javascript -modules that are pre-compiled. - diff --git a/ios/crypto.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ios/crypto.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/ios/crypto.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/ios/crypto.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/ios/crypto.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/ios/crypto.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/ios/crypto.xcodeproj/project.xcworkspace/xcuserdata/hknoechel.xcuserdatad/UserInterfaceState.xcuserstate b/ios/crypto.xcodeproj/project.xcworkspace/xcuserdata/hknoechel.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000000000000000000000000000000000000..f33492f2aea1df93c321069e8aa36610c409138c GIT binary patch literal 23523 zcmeIad3;kv7ce|??@iY)>_cOWHdCzyUYErf=pETltv)ED(b{m}qago=>?4MZhq2pWn; zp;}}?W6)Sshw4!ynvABP>1YO;gPuim(LA&Utwrn5dh`a`fHtB{=uNa4y@j@*chI}& zJ+uSuM4zC2=xeke9Y6=sx9B@`0{w)3L%*ZT=nDD+-Nc^Q3;W>!EX9FXju{+;<8cB` z#7Q_Ar{Hv)fji?aI3M@I1-LgJfCu6dJOq!zRd@^@i^t&!*okN0Irv%pB3_JN!W;1> z{3hOv-@;q)+juK}2XDh4;1BV~_!GPzAHWCkA$$y9z!&i^_!9mV|Av3Zm+=*bWjIE_ zcrc!f7vs(NFaeB|kugC`CngwkOb8Rh#4^c@hDm2K7#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-^qlu-fpZVUOVx!>5MN4PP4e i8TK0v8V(zd8jc$-8h$riZ?#q!*RP + + + + SchemeUserState + + Build & Test.xcscheme + + orderHint + 1 + + crypto.xcscheme + + orderHint + 0 + + + + diff --git a/ios/example/app.js b/ios/example/app.js index 90747c4..3aa850c 100644 --- a/ios/example/app.js +++ b/ios/example/app.js @@ -1,3 +1,6 @@ +// Load the crypto modules +var Crypto = require('ti.crypto'); + var App = { controllers:{}, crypto:null, @@ -17,9 +20,6 @@ var App = { } }; -// Load the crypto modules -var Crypto = require('ti.crypto'); - Ti.include('ui.js'); Ti.include('test.js'); diff --git a/ios/hooks/README b/ios/hooks/README deleted file mode 100644 index 66b10a8..0000000 --- a/ios/hooks/README +++ /dev/null @@ -1 +0,0 @@ -These files are not yet supported as of 1.4.0 but will be in a near future release. diff --git a/ios/hooks/add.py b/ios/hooks/add.py deleted file mode 100644 index 04e1c1d..0000000 --- a/ios/hooks/add.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python -# -# This is the module project add hook that will be -# called when your module is added to a project -# -import os, sys - -def dequote(s): - if s[0:1] == '"': - return s[1:-1] - return s - -def main(args,argc): - # You will get the following command line arguments - # in the following order: - # - # project_dir = the full path to the project root directory - # project_type = the type of project (desktop, mobile, ipad) - # project_name = the name of the project - # - project_dir = dequote(os.path.expanduser(args[1])) - project_type = dequote(args[2]) - project_name = dequote(args[3]) - - # TODO: write your add hook here (optional) - - - # exit - sys.exit(0) - - - -if __name__ == '__main__': - main(sys.argv,len(sys.argv)) - diff --git a/ios/hooks/install.py b/ios/hooks/install.py deleted file mode 100644 index b423fe9..0000000 --- a/ios/hooks/install.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python -# -# This is the module install hook that will be -# called when your module is first installed -# -import os, sys - -def main(args,argc): - - # TODO: write your install hook here (optional) - - # exit - sys.exit(0) - - - -if __name__ == '__main__': - main(sys.argv,len(sys.argv)) - diff --git a/ios/hooks/remove.py b/ios/hooks/remove.py deleted file mode 100644 index f92a234..0000000 --- a/ios/hooks/remove.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python -# -# This is the module project remove hook that will be -# called when your module is remove from a project -# -import os, sys - -def dequote(s): - if s[0:1] == '"': - return s[1:-1] - return s - -def main(args,argc): - # You will get the following command line arguments - # in the following order: - # - # project_dir = the full path to the project root directory - # project_type = the type of project (desktop, mobile, ipad) - # project_name = the name of the project - # - project_dir = dequote(os.path.expanduser(args[1])) - project_type = dequote(args[2]) - project_name = dequote(args[3]) - - # TODO: write your remove hook here (optional) - - # exit - sys.exit(0) - - - -if __name__ == '__main__': - main(sys.argv,len(sys.argv)) - diff --git a/ios/hooks/uninstall.py b/ios/hooks/uninstall.py deleted file mode 100644 index a7ffd91..0000000 --- a/ios/hooks/uninstall.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python -# -# This is the module uninstall hook that will be -# called when your module is uninstalled -# -import os, sys - -def main(args,argc): - - # TODO: write your uninstall hook here (optional) - - # exit - sys.exit(0) - - -if __name__ == '__main__': - main(sys.argv,len(sys.argv)) - diff --git a/ios/manifest b/ios/manifest index 2eb809d..03b0ba4 100644 --- a/ios/manifest +++ b/ios/manifest @@ -2,17 +2,16 @@ # this is your module manifest and used by Titanium # during compilation, packaging, distribution, etc. # -version: 1.3.0 +version: 1.3.1 architectures: armv7 i386 x86_64 arm64 description: This module provides access to various encryption and decryption algorithms, and string encodings. author: Jeff English license: Appcelerator Commercial License -copyright: Copyright (c) 2010-2013 by Appcelerator, Inc. - +copyright: Copyright (c) 2010-2018 by Appcelerator, Inc. # these should not be edited name: crypto moduleid: ti.crypto guid: 5041eaca-a895-4229-a44b-de2f582c9133 platform: iphone -minsdk: 5.1.0 +minsdk: 5.5.0 diff --git a/ios/platform/README b/ios/platform/README deleted file mode 100644 index 7ac991c..0000000 --- a/ios/platform/README +++ /dev/null @@ -1,3 +0,0 @@ -You can place platform-specific files here in sub-folders named "android" and/or "iphone", just as you can with normal Titanium Mobile SDK projects. Any folders and files you place here will be merged with the platform-specific files in a Titanium Mobile project that uses this module. - -When a Titanium Mobile project that uses this module is built, the files from this platform/ folder will be treated the same as files (if any) from the Titanium Mobile project's platform/ folder. diff --git a/ios/titanium.xcconfig b/ios/titanium.xcconfig index 42086c7..af446d0 100644 --- a/ios/titanium.xcconfig +++ b/ios/titanium.xcconfig @@ -4,7 +4,7 @@ // OF YOUR TITANIUM SDK YOU'RE BUILDING FOR // // -TITANIUM_SDK_VERSION = 5.1.2.GA +TITANIUM_SDK_VERSION = 7.2.0.GA // From 0086d18e2611591d637a999855af8b93ee850e0f Mon Sep 17 00:00:00 2001 From: hansemannn Date: Wed, 15 Aug 2018 11:40:35 +0200 Subject: [PATCH 2/5] chore: lint all iOS sources --- ios/.clang-format | 96 ++++ ios/Classes/TiCryptoBase64Transcoder.c | 301 ++++++------ ios/Classes/TiCryptoBase64Transcoder.h | 17 +- ios/Classes/TiCryptoCryptorProxy.h | 6 +- ios/Classes/TiCryptoCryptorProxy.m | 621 ++++++++++++------------ ios/Classes/TiCryptoKeyChainItemProxy.h | 6 +- ios/Classes/TiCryptoKeyChainItemProxy.m | 360 +++++++------- ios/Classes/TiCryptoModule.h | 19 +- ios/Classes/TiCryptoModule.m | 328 ++++++------- ios/Classes/TiCryptoModuleAssets.h | 5 +- ios/Classes/TiCryptoModuleAssets.m | 6 +- ios/Classes/TiCryptoUtils.h | 8 +- ios/Classes/TiCryptoUtils.m | 126 ++--- 13 files changed, 978 insertions(+), 921 deletions(-) create mode 100644 ios/.clang-format diff --git a/ios/.clang-format b/ios/.clang-format new file mode 100644 index 0000000..155e5a1 --- /dev/null +++ b/ios/.clang-format @@ -0,0 +1,96 @@ +--- +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: false +AlignOperands: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false +BreakBeforeBinaryOperators: All +BreakBeforeBraces: WebKit +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: true +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +BreakBeforeInheritanceComma: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '$' +IndentCaseLabels: false +IndentWidth: 2 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never +... diff --git a/ios/Classes/TiCryptoBase64Transcoder.c b/ios/Classes/TiCryptoBase64Transcoder.c index 06bae01..f12367c 100644 --- a/ios/Classes/TiCryptoBase64Transcoder.c +++ b/ios/Classes/TiCryptoBase64Transcoder.c @@ -31,22 +31,22 @@ #include static const u_int8_t kBase64EncodeTable[64] = { - /* 0 */ 'A', /* 1 */ 'B', /* 2 */ 'C', /* 3 */ 'D', - /* 4 */ 'E', /* 5 */ 'F', /* 6 */ 'G', /* 7 */ 'H', - /* 8 */ 'I', /* 9 */ 'J', /* 10 */ 'K', /* 11 */ 'L', - /* 12 */ 'M', /* 13 */ 'N', /* 14 */ 'O', /* 15 */ 'P', - /* 16 */ 'Q', /* 17 */ 'R', /* 18 */ 'S', /* 19 */ 'T', - /* 20 */ 'U', /* 21 */ 'V', /* 22 */ 'W', /* 23 */ 'X', - /* 24 */ 'Y', /* 25 */ 'Z', /* 26 */ 'a', /* 27 */ 'b', - /* 28 */ 'c', /* 29 */ 'd', /* 30 */ 'e', /* 31 */ 'f', - /* 32 */ 'g', /* 33 */ 'h', /* 34 */ 'i', /* 35 */ 'j', - /* 36 */ 'k', /* 37 */ 'l', /* 38 */ 'm', /* 39 */ 'n', - /* 40 */ 'o', /* 41 */ 'p', /* 42 */ 'q', /* 43 */ 'r', - /* 44 */ 's', /* 45 */ 't', /* 46 */ 'u', /* 47 */ 'v', - /* 48 */ 'w', /* 49 */ 'x', /* 50 */ 'y', /* 51 */ 'z', - /* 52 */ '0', /* 53 */ '1', /* 54 */ '2', /* 55 */ '3', - /* 56 */ '4', /* 57 */ '5', /* 58 */ '6', /* 59 */ '7', - /* 60 */ '8', /* 61 */ '9', /* 62 */ '+', /* 63 */ '/' + /* 0 */ 'A', /* 1 */ 'B', /* 2 */ 'C', /* 3 */ 'D', + /* 4 */ 'E', /* 5 */ 'F', /* 6 */ 'G', /* 7 */ 'H', + /* 8 */ 'I', /* 9 */ 'J', /* 10 */ 'K', /* 11 */ 'L', + /* 12 */ 'M', /* 13 */ 'N', /* 14 */ 'O', /* 15 */ 'P', + /* 16 */ 'Q', /* 17 */ 'R', /* 18 */ 'S', /* 19 */ 'T', + /* 20 */ 'U', /* 21 */ 'V', /* 22 */ 'W', /* 23 */ 'X', + /* 24 */ 'Y', /* 25 */ 'Z', /* 26 */ 'a', /* 27 */ 'b', + /* 28 */ 'c', /* 29 */ 'd', /* 30 */ 'e', /* 31 */ 'f', + /* 32 */ 'g', /* 33 */ 'h', /* 34 */ 'i', /* 35 */ 'j', + /* 36 */ 'k', /* 37 */ 'l', /* 38 */ 'm', /* 39 */ 'n', + /* 40 */ 'o', /* 41 */ 'p', /* 42 */ 'q', /* 43 */ 'r', + /* 44 */ 's', /* 45 */ 't', /* 46 */ 'u', /* 47 */ 'v', + /* 48 */ 'w', /* 49 */ 'x', /* 50 */ 'y', /* 51 */ 'z', + /* 52 */ '0', /* 53 */ '1', /* 54 */ '2', /* 55 */ '3', + /* 56 */ '4', /* 57 */ '5', /* 58 */ '6', /* 59 */ '7', + /* 60 */ '8', /* 61 */ '9', /* 62 */ '+', /* 63 */ '/' }; /* @@ -58,38 +58,38 @@ static const u_int8_t kBase64EncodeTable[64] = { */ static const int8_t kTiCryptoBase64DecodeTable[128] = { - /* 0x00 */ -5, /* 0x01 */ -3, /* 0x02 */ -3, /* 0x03 */ -3, - /* 0x04 */ -3, /* 0x05 */ -3, /* 0x06 */ -3, /* 0x07 */ -3, - /* 0x08 */ -3, /* 0x09 */ -2, /* 0x0a */ -2, /* 0x0b */ -2, - /* 0x0c */ -2, /* 0x0d */ -2, /* 0x0e */ -3, /* 0x0f */ -3, - /* 0x10 */ -3, /* 0x11 */ -3, /* 0x12 */ -3, /* 0x13 */ -3, - /* 0x14 */ -3, /* 0x15 */ -3, /* 0x16 */ -3, /* 0x17 */ -3, - /* 0x18 */ -3, /* 0x19 */ -3, /* 0x1a */ -3, /* 0x1b */ -3, - /* 0x1c */ -3, /* 0x1d */ -3, /* 0x1e */ -3, /* 0x1f */ -3, - /* ' ' */ -2, /* '!' */ -3, /* '"' */ -3, /* '#' */ -3, - /* '$' */ -3, /* '%' */ -3, /* '&' */ -3, /* ''' */ -3, - /* '(' */ -3, /* ')' */ -3, /* '*' */ -3, /* '+' */ 62, - /* ',' */ -3, /* '-' */ -3, /* '.' */ -3, /* '/' */ 63, - /* '0' */ 52, /* '1' */ 53, /* '2' */ 54, /* '3' */ 55, - /* '4' */ 56, /* '5' */ 57, /* '6' */ 58, /* '7' */ 59, - /* '8' */ 60, /* '9' */ 61, /* ':' */ -3, /* ';' */ -3, - /* '<' */ -3, /* '=' */ -1, /* '>' */ -3, /* '?' */ -3, - /* '@' */ -3, /* 'A' */ 0, /* 'B' */ 1, /* 'C' */ 2, - /* 'D' */ 3, /* 'E' */ 4, /* 'F' */ 5, /* 'G' */ 6, - /* 'H' */ 7, /* 'I' */ 8, /* 'J' */ 9, /* 'K' */ 10, - /* 'L' */ 11, /* 'M' */ 12, /* 'N' */ 13, /* 'O' */ 14, - /* 'P' */ 15, /* 'Q' */ 16, /* 'R' */ 17, /* 'S' */ 18, - /* 'T' */ 19, /* 'U' */ 20, /* 'V' */ 21, /* 'W' */ 22, - /* 'X' */ 23, /* 'Y' */ 24, /* 'Z' */ 25, /* '[' */ -3, - /* '\' */ -3, /* ']' */ -3, /* '^' */ -3, /* '_' */ -3, - /* '`' */ -3, /* 'a' */ 26, /* 'b' */ 27, /* 'c' */ 28, - /* 'd' */ 29, /* 'e' */ 30, /* 'f' */ 31, /* 'g' */ 32, - /* 'h' */ 33, /* 'i' */ 34, /* 'j' */ 35, /* 'k' */ 36, - /* 'l' */ 37, /* 'm' */ 38, /* 'n' */ 39, /* 'o' */ 40, - /* 'p' */ 41, /* 'q' */ 42, /* 'r' */ 43, /* 's' */ 44, - /* 't' */ 45, /* 'u' */ 46, /* 'v' */ 47, /* 'w' */ 48, - /* 'x' */ 49, /* 'y' */ 50, /* 'z' */ 51, /* '{' */ -3, - /* '|' */ -3, /* '}' */ -3, /* '~' */ -3, /* 0x7f */ -3 + /* 0x00 */ -5, /* 0x01 */ -3, /* 0x02 */ -3, /* 0x03 */ -3, + /* 0x04 */ -3, /* 0x05 */ -3, /* 0x06 */ -3, /* 0x07 */ -3, + /* 0x08 */ -3, /* 0x09 */ -2, /* 0x0a */ -2, /* 0x0b */ -2, + /* 0x0c */ -2, /* 0x0d */ -2, /* 0x0e */ -3, /* 0x0f */ -3, + /* 0x10 */ -3, /* 0x11 */ -3, /* 0x12 */ -3, /* 0x13 */ -3, + /* 0x14 */ -3, /* 0x15 */ -3, /* 0x16 */ -3, /* 0x17 */ -3, + /* 0x18 */ -3, /* 0x19 */ -3, /* 0x1a */ -3, /* 0x1b */ -3, + /* 0x1c */ -3, /* 0x1d */ -3, /* 0x1e */ -3, /* 0x1f */ -3, + /* ' ' */ -2, /* '!' */ -3, /* '"' */ -3, /* '#' */ -3, + /* '$' */ -3, /* '%' */ -3, /* '&' */ -3, /* ''' */ -3, + /* '(' */ -3, /* ')' */ -3, /* '*' */ -3, /* '+' */ 62, + /* ',' */ -3, /* '-' */ -3, /* '.' */ -3, /* '/' */ 63, + /* '0' */ 52, /* '1' */ 53, /* '2' */ 54, /* '3' */ 55, + /* '4' */ 56, /* '5' */ 57, /* '6' */ 58, /* '7' */ 59, + /* '8' */ 60, /* '9' */ 61, /* ':' */ -3, /* ';' */ -3, + /* '<' */ -3, /* '=' */ -1, /* '>' */ -3, /* '?' */ -3, + /* '@' */ -3, /* 'A' */ 0, /* 'B' */ 1, /* 'C' */ 2, + /* 'D' */ 3, /* 'E' */ 4, /* 'F' */ 5, /* 'G' */ 6, + /* 'H' */ 7, /* 'I' */ 8, /* 'J' */ 9, /* 'K' */ 10, + /* 'L' */ 11, /* 'M' */ 12, /* 'N' */ 13, /* 'O' */ 14, + /* 'P' */ 15, /* 'Q' */ 16, /* 'R' */ 17, /* 'S' */ 18, + /* 'T' */ 19, /* 'U' */ 20, /* 'V' */ 21, /* 'W' */ 22, + /* 'X' */ 23, /* 'Y' */ 24, /* 'Z' */ 25, /* '[' */ -3, + /* '\' */ -3, /* ']' */ -3, /* '^' */ -3, /* '_' */ -3, + /* '`' */ -3, /* 'a' */ 26, /* 'b' */ 27, /* 'c' */ 28, + /* 'd' */ 29, /* 'e' */ 30, /* 'f' */ 31, /* 'g' */ 32, + /* 'h' */ 33, /* 'i' */ 34, /* 'j' */ 35, /* 'k' */ 36, + /* 'l' */ 37, /* 'm' */ 38, /* 'n' */ 39, /* 'o' */ 40, + /* 'p' */ 41, /* 'q' */ 42, /* 'r' */ 43, /* 's' */ 44, + /* 't' */ 45, /* 'u' */ 46, /* 'v' */ 47, /* 'w' */ 48, + /* 'x' */ 49, /* 'y' */ 50, /* 'z' */ 51, /* '{' */ -3, + /* '|' */ -3, /* '}' */ -3, /* '~' */ -3, /* 0x7f */ -3 }; static const u_int8_t kBits_00000011 = 0x03; @@ -103,130 +103,109 @@ static const u_int8_t kBits_11111100 = 0xFC; size_t TiCryptoEstimateBas64EncodedDataSize(size_t inDataSize) { - size_t theEncodedDataSize = (int)ceil(inDataSize / 3.0) * 4; - theEncodedDataSize = theEncodedDataSize / 72 * 74 + theEncodedDataSize % 72; - return(theEncodedDataSize); + size_t theEncodedDataSize = (int)ceil(inDataSize / 3.0) * 4; + theEncodedDataSize = theEncodedDataSize / 72 * 74 + theEncodedDataSize % 72; + return (theEncodedDataSize); } size_t TiCryptoEstimateBas64DecodedDataSize(size_t inDataSize) { - size_t theDecodedDataSize = (int)ceil(inDataSize / 4.0) * 3; - //theDecodedDataSize = theDecodedDataSize / 72 * 74 + theDecodedDataSize % 72; - return(theDecodedDataSize); + size_t theDecodedDataSize = (int)ceil(inDataSize / 4.0) * 3; + //theDecodedDataSize = theDecodedDataSize / 72 * 74 + theDecodedDataSize % 72; + return (theDecodedDataSize); } bool TiCryptoBase64EncodeData(const void *inInputData, size_t inInputDataSize, char *outOutputData, size_t *ioOutputDataSize) { - size_t theEncodedDataSize = TiCryptoEstimateBas64EncodedDataSize(inInputDataSize); - if (*ioOutputDataSize < theEncodedDataSize) - return(false); - *ioOutputDataSize = theEncodedDataSize; - const u_int8_t *theInPtr = (const u_int8_t *)inInputData; - u_int32_t theInIndex = 0, theOutIndex = 0; - for (; theInIndex < (inInputDataSize / 3) * 3; theInIndex += 3) - { - outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2]; - outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (theInPtr[theInIndex + 1] & kBits_11110000) >> 4]; - outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 1] & kBits_00001111) << 2 | (theInPtr[theInIndex + 2] & kBits_11000000) >> 6]; - outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 2] & kBits_00111111) >> 0]; - if (theOutIndex % 74 == 72) - { - outOutputData[theOutIndex++] = '\r'; - outOutputData[theOutIndex++] = '\n'; - } - } - const size_t theRemainingBytes = inInputDataSize - theInIndex; - if (theRemainingBytes == 1) - { - outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2]; - outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (0 & kBits_11110000) >> 4]; - outOutputData[theOutIndex++] = '='; - outOutputData[theOutIndex++] = '='; - if (theOutIndex % 74 == 72) - { - outOutputData[theOutIndex++] = '\r'; - outOutputData[theOutIndex++] = '\n'; - } - } - else if (theRemainingBytes == 2) - { - outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2]; - outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (theInPtr[theInIndex + 1] & kBits_11110000) >> 4]; - outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 1] & kBits_00001111) << 2 | (0 & kBits_11000000) >> 6]; - outOutputData[theOutIndex++] = '='; - if (theOutIndex % 74 == 72) - { - outOutputData[theOutIndex++] = '\r'; - outOutputData[theOutIndex++] = '\n'; - } - } - // make clang happy + size_t theEncodedDataSize = TiCryptoEstimateBas64EncodedDataSize(inInputDataSize); + if (*ioOutputDataSize < theEncodedDataSize) + return (false); + *ioOutputDataSize = theEncodedDataSize; + const u_int8_t *theInPtr = (const u_int8_t *)inInputData; + u_int32_t theInIndex = 0, theOutIndex = 0; + for (; theInIndex < (inInputDataSize / 3) * 3; theInIndex += 3) { + outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2]; + outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (theInPtr[theInIndex + 1] & kBits_11110000) >> 4]; + outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 1] & kBits_00001111) << 2 | (theInPtr[theInIndex + 2] & kBits_11000000) >> 6]; + outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 2] & kBits_00111111) >> 0]; + if (theOutIndex % 74 == 72) { + outOutputData[theOutIndex++] = '\r'; + outOutputData[theOutIndex++] = '\n'; + } + } + const size_t theRemainingBytes = inInputDataSize - theInIndex; + if (theRemainingBytes == 1) { + outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2]; + outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (0 & kBits_11110000) >> 4]; + outOutputData[theOutIndex++] = '='; + outOutputData[theOutIndex++] = '='; + if (theOutIndex % 74 == 72) { + outOutputData[theOutIndex++] = '\r'; + outOutputData[theOutIndex++] = '\n'; + } + } else if (theRemainingBytes == 2) { + outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2]; + outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (theInPtr[theInIndex + 1] & kBits_11110000) >> 4]; + outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 1] & kBits_00001111) << 2 | (0 & kBits_11000000) >> 6]; + outOutputData[theOutIndex++] = '='; + if (theOutIndex % 74 == 72) { + outOutputData[theOutIndex++] = '\r'; + outOutputData[theOutIndex++] = '\n'; + } + } + // make clang happy #pragma unused(theOutIndex) - return(true); + return (true); } bool TiCryptoBase64DecodeData(const void *inInputData, size_t inInputDataSize, void *ioOutputData, size_t *ioOutputDataSize) { - memset(ioOutputData, '.', *ioOutputDataSize); - - size_t theDecodedDataSize = TiCryptoEstimateBas64DecodedDataSize(inInputDataSize); - if (*ioOutputDataSize < theDecodedDataSize) - return(false); - *ioOutputDataSize = 0; - const u_int8_t *theInPtr = (const u_int8_t *)inInputData; - u_int8_t *theOutPtr = (u_int8_t *)ioOutputData; - size_t theInIndex = 0, theOutIndex = 0; - u_int8_t theOutputOctet; - size_t theSequence = 0; - for (; theInIndex < inInputDataSize; ) - { - int8_t theSextet = 0; - - int8_t theCurrentInputOctet = theInPtr[theInIndex]; - theSextet = kTiCryptoBase64DecodeTable[theCurrentInputOctet]; - if (theSextet == -1) - break; - while (theSextet == -2) - { - theCurrentInputOctet = theInPtr[++theInIndex]; - theSextet = kTiCryptoBase64DecodeTable[theCurrentInputOctet]; - } - while (theSextet == -3) - { - theCurrentInputOctet = theInPtr[++theInIndex]; - theSextet = kTiCryptoBase64DecodeTable[theCurrentInputOctet]; - } - if (theSequence == 0) - { - theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 2 & kBits_11111100; - } - else if (theSequence == 1) - { - theOutputOctet |= (theSextet >- 0 ? theSextet : 0) >> 4 & kBits_00000011; - theOutPtr[theOutIndex++] = theOutputOctet; - } - else if (theSequence == 2) - { - theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 4 & kBits_11110000; - } - else if (theSequence == 3) - { - theOutputOctet |= (theSextet >= 0 ? theSextet : 0) >> 2 & kBits_00001111; - theOutPtr[theOutIndex++] = theOutputOctet; - } - else if (theSequence == 4) - { - theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 6 & kBits_11000000; - } - else if (theSequence == 5) - { - theOutputOctet |= (theSextet >= 0 ? theSextet : 0) >> 0 & kBits_00111111; - theOutPtr[theOutIndex++] = theOutputOctet; - } - theSequence = (theSequence + 1) % 6; - if (theSequence != 2 && theSequence != 4) - theInIndex++; - } - *ioOutputDataSize = theOutIndex; - return(true); + memset(ioOutputData, '.', *ioOutputDataSize); + + size_t theDecodedDataSize = TiCryptoEstimateBas64DecodedDataSize(inInputDataSize); + if (*ioOutputDataSize < theDecodedDataSize) + return (false); + *ioOutputDataSize = 0; + const u_int8_t *theInPtr = (const u_int8_t *)inInputData; + u_int8_t *theOutPtr = (u_int8_t *)ioOutputData; + size_t theInIndex = 0, theOutIndex = 0; + u_int8_t theOutputOctet; + size_t theSequence = 0; + for (; theInIndex < inInputDataSize;) { + int8_t theSextet = 0; + + int8_t theCurrentInputOctet = theInPtr[theInIndex]; + theSextet = kTiCryptoBase64DecodeTable[theCurrentInputOctet]; + if (theSextet == -1) + break; + while (theSextet == -2) { + theCurrentInputOctet = theInPtr[++theInIndex]; + theSextet = kTiCryptoBase64DecodeTable[theCurrentInputOctet]; + } + while (theSextet == -3) { + theCurrentInputOctet = theInPtr[++theInIndex]; + theSextet = kTiCryptoBase64DecodeTable[theCurrentInputOctet]; + } + if (theSequence == 0) { + theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 2 & kBits_11111100; + } else if (theSequence == 1) { + theOutputOctet |= (theSextet > -0 ? theSextet : 0) >> 4 & kBits_00000011; + theOutPtr[theOutIndex++] = theOutputOctet; + } else if (theSequence == 2) { + theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 4 & kBits_11110000; + } else if (theSequence == 3) { + theOutputOctet |= (theSextet >= 0 ? theSextet : 0) >> 2 & kBits_00001111; + theOutPtr[theOutIndex++] = theOutputOctet; + } else if (theSequence == 4) { + theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 6 & kBits_11000000; + } else if (theSequence == 5) { + theOutputOctet |= (theSextet >= 0 ? theSextet : 0) >> 0 & kBits_00111111; + theOutPtr[theOutIndex++] = theOutputOctet; + } + theSequence = (theSequence + 1) % 6; + if (theSequence != 2 && theSequence != 4) + theInIndex++; + } + *ioOutputDataSize = theOutIndex; + return (true); } diff --git a/ios/Classes/TiCryptoBase64Transcoder.h b/ios/Classes/TiCryptoBase64Transcoder.h index 45f0447..8a0c3b5 100644 --- a/ios/Classes/TiCryptoBase64Transcoder.h +++ b/ios/Classes/TiCryptoBase64Transcoder.h @@ -25,20 +25,19 @@ * */ -#include #include +#include #if defined(__cplusplus) extern "C" { #endif - - size_t TiCryptoEstimateBas64EncodedDataSize(size_t inDataSize); - size_t TiCryptoEstimateBas64DecodedDataSize(size_t inDataSize); - - bool TiCryptoBase64EncodeData(const void *inInputData, size_t inInputDataSize, char *outOutputData, size_t *ioOutputDataSize); - bool TiCryptoBase64DecodeData(const void *inInputData, size_t inInputDataSize, void *ioOutputData, size_t *ioOutputDataSize); - + +size_t TiCryptoEstimateBas64EncodedDataSize(size_t inDataSize); +size_t TiCryptoEstimateBas64DecodedDataSize(size_t inDataSize); + +bool TiCryptoBase64EncodeData(const void *inInputData, size_t inInputDataSize, char *outOutputData, size_t *ioOutputDataSize); +bool TiCryptoBase64DecodeData(const void *inInputData, size_t inInputDataSize, void *ioOutputData, size_t *ioOutputDataSize); + #if defined(__cplusplus) } #endif - diff --git a/ios/Classes/TiCryptoCryptorProxy.h b/ios/Classes/TiCryptoCryptorProxy.h index 28cb85e..d0d3024 100644 --- a/ios/Classes/TiCryptoCryptorProxy.h +++ b/ios/Classes/TiCryptoCryptorProxy.h @@ -9,9 +9,9 @@ @interface TiCryptoCryptorProxy : TiProxy { -@private - CCCryptorRef cryptorRef; - BOOL resizeBuffer; + @private + CCCryptorRef cryptorRef; + BOOL resizeBuffer; } @end diff --git a/ios/Classes/TiCryptoCryptorProxy.m b/ios/Classes/TiCryptoCryptorProxy.m index 873fe7c..80cb439 100644 --- a/ios/Classes/TiCryptoCryptorProxy.m +++ b/ios/Classes/TiCryptoCryptorProxy.m @@ -4,8 +4,8 @@ * Please see the LICENSE included with this distribution for details. */ -#import "TiCryptoModule.h" #import "TiCryptoCryptorProxy.h" +#import "TiCryptoModule.h" #import "TiUtils.h" @@ -13,378 +13,377 @@ @implementation TiCryptoCryptorProxy #pragma mark Proxy Lifecycle --(id)init +- (id)init { - // Default setting is to resize the output buffer to fit the required size - resizeBuffer = YES; - - return [super init]; + // Default setting is to resize the output buffer to fit the required size + resizeBuffer = YES; + + return [super init]; } --(void)_destroy +- (void)_destroy { - // Clean-up and release the cryptor - if (cryptorRef != nil) { - CCCryptorRelease(cryptorRef); - cryptorRef = nil; - } - [super _destroy]; + // Clean-up and release the cryptor + if (cryptorRef != nil) { + CCCryptorRelease(cryptorRef); + cryptorRef = nil; + } + [super _destroy]; } #pragma mark resizeBuffer property // resizeBuffer property setter / getter --(void)setResizeBuffer:(id)value +- (void)setResizeBuffer:(id)value { - resizeBuffer = [TiUtils boolValue:value def:NO]; + resizeBuffer = [TiUtils boolValue:value def:NO]; } --(id)getResizeBuffer +- (id)getResizeBuffer { - return NUMBOOL(resizeBuffer); + return NUMBOOL(resizeBuffer); } #pragma mark Argument Processing Helpers // Local structure for encryption options typedef struct { - CCOperation operation; - CCAlgorithm algorithm; - CCOptions options; - TiBuffer* key; - TiBuffer* initializationVector; + CCOperation operation; + CCAlgorithm algorithm; + CCOptions options; + TiBuffer *key; + TiBuffer *initializationVector; } CryptOptions; // Local structure for encryption data typedef struct { - TiBuffer* dataInBuffer; - TiBuffer* dataOutBuffer; - int dataInLength; - int dataOutLength; + TiBuffer *dataInBuffer; + TiBuffer *dataOutBuffer; + int dataInLength; + int dataOutLength; } CryptData; --(void)prepareCryptOptions:(CryptOptions*)cryptOptions +- (void)prepareCryptOptions:(CryptOptions *)cryptOptions { - cryptOptions->operation = [TiUtils intValue:[self valueForUndefinedKey:@"operation"] def:kCCEncrypt]; - cryptOptions->algorithm = [TiUtils intValue:[self valueForUndefinedKey:@"algorithm"] def:kCCAlgorithmAES128]; - cryptOptions->options = [TiUtils intValue:[self valueForUndefinedKey:@"options"] def:0]; - - // Retrieve the key - cryptOptions->key = [self valueForUndefinedKey:@"key"]; - ENSURE_TYPE(cryptOptions->key,TiBuffer); - - // Retrieve the initialization vector -- it must be a buffer object (preferably created - // from ti.crypto.createBuffer so that it supports binary vector data - cryptOptions->initializationVector = [self valueForUndefinedKey:@"initializationVector"]; - if (cryptOptions->initializationVector) { - ENSURE_TYPE(cryptOptions->initializationVector,TiBuffer); - } + cryptOptions->operation = [TiUtils intValue:[self valueForUndefinedKey:@"operation"] def:kCCEncrypt]; + cryptOptions->algorithm = [TiUtils intValue:[self valueForUndefinedKey:@"algorithm"] def:kCCAlgorithmAES128]; + cryptOptions->options = [TiUtils intValue:[self valueForUndefinedKey:@"options"] def:0]; + + // Retrieve the key + cryptOptions->key = [self valueForUndefinedKey:@"key"]; + ENSURE_TYPE(cryptOptions->key, TiBuffer); + + // Retrieve the initialization vector -- it must be a buffer object (preferably created + // from ti.crypto.createBuffer so that it supports binary vector data + cryptOptions->initializationVector = [self valueForUndefinedKey:@"initializationVector"]; + if (cryptOptions->initializationVector) { + ENSURE_TYPE(cryptOptions->initializationVector, TiBuffer); + } } --(void)prepareCryptData:(CryptData*)cryptData fromArgs:(id)args +- (void)prepareCryptData:(CryptData *)cryptData fromArgs:(id)args { - enum { - kArgDataIn = 0, // REQUIRED - kArgCountRequired, - kArgDataInLength = kArgCountRequired, // OPTIONAL - kArgDataOut, // OPTIONAL - kArgDataOutLength, // OPTIONAL - kArgCount - }; - - ENSURE_ARG_COUNT(args,kArgCountRequired); - - BOOL hasValue; - - // Get the input buffer. - ENSURE_ARG_AT_INDEX(cryptData->dataInBuffer,args,kArgDataIn,TiBuffer); - - // Get the input buffer length. If no length is provided then use the length of the buffer. - ENSURE_INT_OR_NIL_AT_INDEX(cryptData->dataInLength,args,kArgDataInLength,hasValue); - if (!hasValue || (cryptData->dataInLength < 0)) { - cryptData->dataInLength = [cryptData->dataInBuffer length].intValue; - } - - // Get the output buffer. If no output buffer is specified then use the input buffer for output (in-place) - ENSURE_ARG_OR_NIL_AT_INDEX(cryptData->dataOutBuffer,args,kArgDataOut,TiBuffer); - if (cryptData->dataOutBuffer == nil) { - cryptData->dataOutBuffer = cryptData->dataInBuffer; - } - - // Get the output buffer length. If no length is provided then calculate the length needed for the buffer. - ENSURE_INT_OR_NIL_AT_INDEX(cryptData->dataOutLength,args,kArgDataOutLength,hasValue); - if (!hasValue || (cryptData->dataOutLength < 0)) { - cryptData->dataOutLength = [cryptData->dataOutBuffer length].intValue; - } + enum { + kArgDataIn = 0, // REQUIRED + kArgCountRequired, + kArgDataInLength = kArgCountRequired, // OPTIONAL + kArgDataOut, // OPTIONAL + kArgDataOutLength, // OPTIONAL + kArgCount + }; + + ENSURE_ARG_COUNT(args, kArgCountRequired); + + BOOL hasValue; + + // Get the input buffer. + ENSURE_ARG_AT_INDEX(cryptData->dataInBuffer, args, kArgDataIn, TiBuffer); + + // Get the input buffer length. If no length is provided then use the length of the buffer. + ENSURE_INT_OR_NIL_AT_INDEX(cryptData->dataInLength, args, kArgDataInLength, hasValue); + if (!hasValue || (cryptData->dataInLength < 0)) { + cryptData->dataInLength = [cryptData->dataInBuffer length].intValue; + } + + // Get the output buffer. If no output buffer is specified then use the input buffer for output (in-place) + ENSURE_ARG_OR_NIL_AT_INDEX(cryptData->dataOutBuffer, args, kArgDataOut, TiBuffer); + if (cryptData->dataOutBuffer == nil) { + cryptData->dataOutBuffer = cryptData->dataInBuffer; + } + + // Get the output buffer length. If no length is provided then calculate the length needed for the buffer. + ENSURE_INT_OR_NIL_AT_INDEX(cryptData->dataOutLength, args, kArgDataOutLength, hasValue); + if (!hasValue || (cryptData->dataOutLength < 0)) { + cryptData->dataOutLength = [cryptData->dataOutBuffer length].intValue; + } } --(void)prepareFinalCryptData:(CryptData*)cryptData fromArgs:(id)args +- (void)prepareFinalCryptData:(CryptData *)cryptData fromArgs:(id)args { - enum { - kArgDataOut = 0, // REQUIRED - kArgCountRequired, - kArgDataOutLength = kArgCountRequired, // OPTIONAL - kArgCount - }; - - ENSURE_ARG_COUNT(args,kArgCountRequired); - BOOL hasValue; - - // Get the output buffer. - ENSURE_ARG_AT_INDEX(cryptData->dataOutBuffer,args,kArgDataOut,TiBuffer); - - // Get the output buffer length. If no length is provided then use the length of the buffer. - ENSURE_INT_OR_NIL_AT_INDEX(cryptData->dataOutLength,args,kArgDataOutLength,hasValue); - if (!hasValue || (cryptData->dataOutLength < 0)) { - cryptData->dataOutLength = [cryptData->dataOutBuffer length].intValue; - } + enum { + kArgDataOut = 0, // REQUIRED + kArgCountRequired, + kArgDataOutLength = kArgCountRequired, // OPTIONAL + kArgCount + }; + + ENSURE_ARG_COUNT(args, kArgCountRequired); + BOOL hasValue; + + // Get the output buffer. + ENSURE_ARG_AT_INDEX(cryptData->dataOutBuffer, args, kArgDataOut, TiBuffer); + + // Get the output buffer length. If no length is provided then use the length of the buffer. + ENSURE_INT_OR_NIL_AT_INDEX(cryptData->dataOutLength, args, kArgDataOutLength, hasValue); + if (!hasValue || (cryptData->dataOutLength < 0)) { + cryptData->dataOutLength = [cryptData->dataOutBuffer length].intValue; + } } #pragma mark Cryptographic Context Methods --(CCCryptorRef)cryptor +- (CCCryptorRef)cryptor { - if (cryptorRef == nil) { - CryptOptions cryptOptions; - [self prepareCryptOptions:&cryptOptions]; - - // Create the cryptor object that will be used for stream encryption - CCCryptorStatus result = CCCryptorCreate(cryptOptions.operation, - cryptOptions.algorithm, - cryptOptions.options, - [[cryptOptions.key data] bytes], - [cryptOptions.key length].intValue, - [[cryptOptions.initializationVector data] bytes], - &cryptorRef); - - if (result != kCCSuccess) { - NSLog(@"[ERROR] Error creating cryptor - %d", result); - return nil; - } - } - - return cryptorRef; + if (cryptorRef == nil) { + CryptOptions cryptOptions; + [self prepareCryptOptions:&cryptOptions]; + + // Create the cryptor object that will be used for stream encryption + CCCryptorStatus result = CCCryptorCreate(cryptOptions.operation, + cryptOptions.algorithm, + cryptOptions.options, + [[cryptOptions.key data] bytes], + [cryptOptions.key length].intValue, + [[cryptOptions.initializationVector data] bytes], + &cryptorRef); + + if (result != kCCSuccess) { + NSLog(@"[ERROR] Error creating cryptor - %d", result); + return nil; + } + } + + return cryptorRef; } --(NSNumber*)getOutputLength:(id)args +- (NSNumber *)getOutputLength:(id)args { - enum { - kArgLength = 0, - kArgFinal = 1, - kArgCount - }; - - ENSURE_ARG_COUNT(args,kArgCount); - - CCCryptorRef cryptor = [self cryptor]; - if (cryptor) { - int length = [TiUtils intValue:[args objectAtIndex:kArgLength] def:-1]; - if (length < 0) { - length = 0; - } - - BOOL final = [TiUtils boolValue:[args objectAtIndex:kArgFinal] def:NO]; - return [NSNumber numberWithUnsignedInteger: CCCryptorGetOutputLength(cryptor, (size_t)length, final)]; - } - - return NUMINT(0); -} + enum { + kArgLength = 0, + kArgFinal = 1, + kArgCount + }; + + ENSURE_ARG_COUNT(args, kArgCount); + + CCCryptorRef cryptor = [self cryptor]; + if (cryptor) { + int length = [TiUtils intValue:[args objectAtIndex:kArgLength] def:-1]; + if (length < 0) { + length = 0; + } --(NSNumber*)update:(id)args -{ - CCCryptorRef cryptor = [self cryptor]; - if (cryptor) { - CryptData cryptData; - [self prepareCryptData:&cryptData fromArgs:args]; - - // If resize output buffer is specified, then set the output buffer size so that it is - // large enough to hold the result - if (resizeBuffer) { - int neededLength = (int)CCCryptorGetOutputLength(cryptor,cryptData.dataInLength,NO); - if (neededLength == 0) { - neededLength = cryptData.dataInLength; - } - // Call 'setLength' to make sure that the TiBuffer object allocates the memory for the data - if (neededLength > cryptData.dataOutLength) { - cryptData.dataOutLength = neededLength; - [cryptData.dataOutBuffer setLength:NUMINT(neededLength)]; - } - } - - size_t numBytesMoved = 0; - CCCryptorStatus result = CCCryptorUpdate(cryptor, - [[cryptData.dataInBuffer data] bytes], - (size_t)cryptData.dataInLength, - [[cryptData.dataOutBuffer data] mutableBytes], - (size_t)cryptData.dataOutLength, - &numBytesMoved); - - if (result == kCCSuccess) { - if (resizeBuffer) { - [cryptData.dataOutBuffer setLength:[NSNumber numberWithUnsignedInteger: numBytesMoved]]; - } - } else { - NSLog(@"[ERROR] Error during crypt operation - %d", result); - } - - return (result == kCCSuccess) ? [NSNumber numberWithUnsignedInteger: numBytesMoved] : NUMINT(result); - } - - return NUMINT(kCCError); + BOOL final = [TiUtils boolValue:[args objectAtIndex:kArgFinal] def:NO]; + return [NSNumber numberWithUnsignedInteger:CCCryptorGetOutputLength(cryptor, (size_t)length, final)]; + } + + return NUMINT(0); } --(NSNumber*)finish:(id)args +- (NSNumber *)update:(id)args { - CCCryptorRef cryptor = [self cryptor]; - if (cryptor) { - CryptData cryptData; - [self prepareFinalCryptData:&cryptData fromArgs:args]; - - // If resize output buffer is specified, then set the output buffer size so that it is - // large enough to hold the result - if (resizeBuffer) { - int neededLength = (int)CCCryptorGetOutputLength(cryptor,0,YES); - // Call 'setLength' to make sure that the TiBuffer object allocates the memory for the data - if (neededLength > cryptData.dataOutLength) { - cryptData.dataOutLength = neededLength; - [cryptData.dataOutBuffer setLength:NUMINT(cryptData.dataOutLength)]; - } - } - - size_t numBytesMoved = 0; - CCCryptorStatus result = CCCryptorFinal(cryptor, - [[cryptData.dataOutBuffer data] mutableBytes], - (size_t)cryptData.dataOutLength, - &numBytesMoved); - - if (result == kCCSuccess) { - if (resizeBuffer) { - [cryptData.dataOutBuffer setLength:[NSNumber numberWithUnsignedInteger: numBytesMoved]]; - } - } else { - NSLog(@"[ERROR] Error during final operation - %d", result); - } - - return (result == kCCSuccess) ? [NSNumber numberWithUnsignedInteger: numBytesMoved] : NUMINT(result); - } - - return NUMINT(kCCError); + CCCryptorRef cryptor = [self cryptor]; + if (cryptor) { + CryptData cryptData; + [self prepareCryptData:&cryptData fromArgs:args]; + + // If resize output buffer is specified, then set the output buffer size so that it is + // large enough to hold the result + if (resizeBuffer) { + int neededLength = (int)CCCryptorGetOutputLength(cryptor, cryptData.dataInLength, NO); + if (neededLength == 0) { + neededLength = cryptData.dataInLength; + } + // Call 'setLength' to make sure that the TiBuffer object allocates the memory for the data + if (neededLength > cryptData.dataOutLength) { + cryptData.dataOutLength = neededLength; + [cryptData.dataOutBuffer setLength:NUMINT(neededLength)]; + } + } + + size_t numBytesMoved = 0; + CCCryptorStatus result = CCCryptorUpdate(cryptor, + [[cryptData.dataInBuffer data] bytes], + (size_t)cryptData.dataInLength, + [[cryptData.dataOutBuffer data] mutableBytes], + (size_t)cryptData.dataOutLength, + &numBytesMoved); + + if (result == kCCSuccess) { + if (resizeBuffer) { + [cryptData.dataOutBuffer setLength:[NSNumber numberWithUnsignedInteger:numBytesMoved]]; + } + } else { + NSLog(@"[ERROR] Error during crypt operation - %d", result); + } + + return (result == kCCSuccess) ? [NSNumber numberWithUnsignedInteger:numBytesMoved] : NUMINT(result); + } + + return NUMINT(kCCError); } +- (NSNumber *)finish:(id)args +{ + CCCryptorRef cryptor = [self cryptor]; + if (cryptor) { + CryptData cryptData; + [self prepareFinalCryptData:&cryptData fromArgs:args]; + + // If resize output buffer is specified, then set the output buffer size so that it is + // large enough to hold the result + if (resizeBuffer) { + int neededLength = (int)CCCryptorGetOutputLength(cryptor, 0, YES); + // Call 'setLength' to make sure that the TiBuffer object allocates the memory for the data + if (neededLength > cryptData.dataOutLength) { + cryptData.dataOutLength = neededLength; + [cryptData.dataOutBuffer setLength:NUMINT(cryptData.dataOutLength)]; + } + } + + size_t numBytesMoved = 0; + CCCryptorStatus result = CCCryptorFinal(cryptor, + [[cryptData.dataOutBuffer data] mutableBytes], + (size_t)cryptData.dataOutLength, + &numBytesMoved); + + if (result == kCCSuccess) { + if (resizeBuffer) { + [cryptData.dataOutBuffer setLength:[NSNumber numberWithUnsignedInteger:numBytesMoved]]; + } + } else { + NSLog(@"[ERROR] Error during final operation - %d", result); + } + + return (result == kCCSuccess) ? [NSNumber numberWithUnsignedInteger:numBytesMoved] : NUMINT(result); + } + + return NUMINT(kCCError); +} --(NSNumber*)reset:(id)args +- (NSNumber *)reset:(id)args { - enum { - kArgInitializationVector = 0, // OPTIONAL - kArgCount - }; - - CCCryptorStatus result = kCCError; - CCCryptorRef cryptor = [self cryptor]; - if (cryptor) { - TiBuffer* initializationVector; - ENSURE_ARG_OR_NIL_AT_INDEX(initializationVector,args,kArgInitializationVector,TiBuffer); - - result = CCCryptorReset(cryptor, - [[initializationVector data] bytes]); - } - - return NUMINT(result); + enum { + kArgInitializationVector = 0, // OPTIONAL + kArgCount + }; + + CCCryptorStatus result = kCCError; + CCCryptorRef cryptor = [self cryptor]; + if (cryptor) { + TiBuffer *initializationVector; + ENSURE_ARG_OR_NIL_AT_INDEX(initializationVector, args, kArgInitializationVector, TiBuffer); + + result = CCCryptorReset(cryptor, + [[initializationVector data] bytes]); + } + + return NUMINT(result); } --(NSNumber*)release:(id)args +- (NSNumber *)release:(id)args { - CCCryptorStatus result = kCCSuccess; - if (cryptorRef != nil) { - result = CCCryptorRelease (cryptorRef); - cryptorRef = nil; - } - - return NUMINT(result); + CCCryptorStatus result = kCCSuccess; + if (cryptorRef != nil) { + result = CCCryptorRelease(cryptorRef); + cryptorRef = nil; + } + + return NUMINT(result); } #pragma mark Single-shot Encryption Methods --(NSNumber*)crypt:(CCOperation)operation args:(id)args +- (NSNumber *)crypt:(CCOperation)operation args:(id)args { - CryptOptions cryptOptions; - [self prepareCryptOptions:&cryptOptions]; - - CryptData cryptData; - [self prepareCryptData:&cryptData fromArgs:args]; - - // If resize output buffer is specified, then set the output buffer size so that it is - // large enough to hold the result. We need to calculate it ourselves here since we don't - // allocate an actual cryptor in this workflow. - if (resizeBuffer) { - int neededLength = cryptData.dataInLength; - switch (cryptOptions.algorithm) { - case kCCAlgorithmAES128: - neededLength += kCCBlockSizeAES128; - break; - case kCCAlgorithmDES: - neededLength += kCCBlockSizeDES*2; - break; - case kCCAlgorithm3DES: - neededLength += kCCBlockSize3DES; - break; - case kCCAlgorithmCAST: - neededLength += kCCBlockSizeCAST; - break; - case kCCAlgorithmRC4: - case kCCAlgorithmRC2: - neededLength += kCCBlockSizeRC2; - break; - } - // Call 'setLength' to make sure that the TiBuffer object allocates the memory for the data - if (neededLength > cryptData.dataOutLength) { - cryptData.dataOutLength = neededLength; - [cryptData.dataOutBuffer setLength:NUMINT(neededLength)]; - } - } - - //NSLog(@"Preparing to crypt"); - //NSLog(@"Input length: %d value: %@", cryptData.dataInLength, [cryptData.dataInBuffer data]); - //NSLog(@"Output length: %d", cryptData.dataOutLength); - //NSLog(@"Operation: %d",cryptOptions.operation); - //NSLog(@"Algorithm: %d",cryptOptions.algorithm); - //NSLog(@"Options: %d",cryptOptions.options); - //NSLog(@"Key: %@", [cryptOptions.key data]); - //NSLog(@"InitializationVector: %@",[cryptOptions.initializationVector data]); - - size_t numBytesMoved = 0; - CCCryptorStatus result = CCCrypt(operation, - cryptOptions.algorithm, - cryptOptions.options, - [[cryptOptions.key data] bytes], - [cryptOptions.key length].intValue, - [[cryptOptions.initializationVector data] bytes], - [[cryptData.dataInBuffer data] bytes], - (size_t)cryptData.dataInLength, - [[cryptData.dataOutBuffer data] mutableBytes], - (size_t)cryptData.dataOutLength, - &numBytesMoved); - - if (result == kCCSuccess) { - if (resizeBuffer) { - [cryptData.dataOutBuffer setLength:[NSNumber numberWithUnsignedInteger: numBytesMoved]]; - } - //NSLog(@"DataOut: %@", [cryptData.dataOutBuffer data]); - } else { - NSLog(@"[ERROR] Error during crypt operation - %d", result); - } - - return (result == kCCSuccess) ? [NSNumber numberWithUnsignedInteger: numBytesMoved] : NUMINT(result); + CryptOptions cryptOptions; + [self prepareCryptOptions:&cryptOptions]; + + CryptData cryptData; + [self prepareCryptData:&cryptData fromArgs:args]; + + // If resize output buffer is specified, then set the output buffer size so that it is + // large enough to hold the result. We need to calculate it ourselves here since we don't + // allocate an actual cryptor in this workflow. + if (resizeBuffer) { + int neededLength = cryptData.dataInLength; + switch (cryptOptions.algorithm) { + case kCCAlgorithmAES128: + neededLength += kCCBlockSizeAES128; + break; + case kCCAlgorithmDES: + neededLength += kCCBlockSizeDES * 2; + break; + case kCCAlgorithm3DES: + neededLength += kCCBlockSize3DES; + break; + case kCCAlgorithmCAST: + neededLength += kCCBlockSizeCAST; + break; + case kCCAlgorithmRC4: + case kCCAlgorithmRC2: + neededLength += kCCBlockSizeRC2; + break; + } + // Call 'setLength' to make sure that the TiBuffer object allocates the memory for the data + if (neededLength > cryptData.dataOutLength) { + cryptData.dataOutLength = neededLength; + [cryptData.dataOutBuffer setLength:NUMINT(neededLength)]; + } + } + + //NSLog(@"Preparing to crypt"); + //NSLog(@"Input length: %d value: %@", cryptData.dataInLength, [cryptData.dataInBuffer data]); + //NSLog(@"Output length: %d", cryptData.dataOutLength); + //NSLog(@"Operation: %d",cryptOptions.operation); + //NSLog(@"Algorithm: %d",cryptOptions.algorithm); + //NSLog(@"Options: %d",cryptOptions.options); + //NSLog(@"Key: %@", [cryptOptions.key data]); + //NSLog(@"InitializationVector: %@",[cryptOptions.initializationVector data]); + + size_t numBytesMoved = 0; + CCCryptorStatus result = CCCrypt(operation, + cryptOptions.algorithm, + cryptOptions.options, + [[cryptOptions.key data] bytes], + [cryptOptions.key length].intValue, + [[cryptOptions.initializationVector data] bytes], + [[cryptData.dataInBuffer data] bytes], + (size_t)cryptData.dataInLength, + [[cryptData.dataOutBuffer data] mutableBytes], + (size_t)cryptData.dataOutLength, + &numBytesMoved); + + if (result == kCCSuccess) { + if (resizeBuffer) { + [cryptData.dataOutBuffer setLength:[NSNumber numberWithUnsignedInteger:numBytesMoved]]; + } + //NSLog(@"DataOut: %@", [cryptData.dataOutBuffer data]); + } else { + NSLog(@"[ERROR] Error during crypt operation - %d", result); + } + + return (result == kCCSuccess) ? [NSNumber numberWithUnsignedInteger:numBytesMoved] : NUMINT(result); } --(NSNumber*)encrypt:(id)args +- (NSNumber *)encrypt:(id)args { - return [self crypt:kCCEncrypt args:args]; + return [self crypt:kCCEncrypt args:args]; } --(NSNumber*)decrypt:(id)args +- (NSNumber *)decrypt:(id)args { - return [self crypt:kCCDecrypt args:args]; + return [self crypt:kCCDecrypt args:args]; } @end diff --git a/ios/Classes/TiCryptoKeyChainItemProxy.h b/ios/Classes/TiCryptoKeyChainItemProxy.h index f5b0edc..6cb110e 100644 --- a/ios/Classes/TiCryptoKeyChainItemProxy.h +++ b/ios/Classes/TiCryptoKeyChainItemProxy.h @@ -8,9 +8,9 @@ @interface TiCryptoKeyChainItemProxy : TiProxy { -@private - NSMutableDictionary *keychainItemData; // The actual keychain item data backing store. - NSMutableDictionary *keychainQuery; // A placeholder for the generic keychain item query used to locate the item + @private + NSMutableDictionary *keychainItemData; // The actual keychain item data backing store. + NSMutableDictionary *keychainQuery; // A placeholder for the generic keychain item query used to locate the item } @end diff --git a/ios/Classes/TiCryptoKeyChainItemProxy.m b/ios/Classes/TiCryptoKeyChainItemProxy.m index 526382f..e0a20b2 100644 --- a/ios/Classes/TiCryptoKeyChainItemProxy.m +++ b/ios/Classes/TiCryptoKeyChainItemProxy.m @@ -11,227 +11,213 @@ @implementation TiCryptoKeyChainItemProxy --(id)init -{ - return [super init]; +- (id)init +{ + return [super init]; } --(void)_destroy -{ - RELEASE_TO_NIL(keychainQuery); - - [super _destroy]; +- (void)_destroy +{ + RELEASE_TO_NIL(keychainQuery); + + [super _destroy]; } - (id)initWithIdentifier:(NSString *)identifier secClass:(id)secClass properties:(NSDictionary *)properties -{ - // Begin Keychain search setup. The keychainQuery leverages the special user - // defined attribute kSecAttrGeneric to distinguish itself between other generic Keychain - // items which may be included by the same application. - keychainQuery = [[NSMutableDictionary alloc] init]; - - [keychainQuery setObject:(id)secClass forKey:(id)kSecClass]; - [keychainQuery setObject:identifier forKey:(id)kSecAttrGeneric]; - - // The keychain access group attribute determines if this item can be shared - // amongst multiple apps whose code signing entitlements contain the same keychain access group. - NSString *accessGroup = [TiUtils stringValue:@"accessGroup" properties:properties]; - if (accessGroup != nil) - { +{ + // Begin Keychain search setup. The keychainQuery leverages the special user + // defined attribute kSecAttrGeneric to distinguish itself between other generic Keychain + // items which may be included by the same application. + keychainQuery = [[NSMutableDictionary alloc] init]; + + [keychainQuery setObject:(id)secClass forKey:(id)kSecClass]; + [keychainQuery setObject:identifier forKey:(id)kSecAttrGeneric]; + + // The keychain access group attribute determines if this item can be shared + // amongst multiple apps whose code signing entitlements contain the same keychain access group. + NSString *accessGroup = [TiUtils stringValue:@"accessGroup" properties:properties]; + if (accessGroup != nil) { #if TARGET_IPHONE_SIMULATOR - // Ignore the access group if running on the iPhone simulator. - // - // Apps that are built for the simulator aren't signed, so there's no keychain access group - // for the simulator to check. This means that all apps can see all keychain items when run - // on the simulator. - // - // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the - // simulator will return -25243 (errSecNoAccessForItem). -#else - [keychainQuery setObject:accessGroup forKey:(id)kSecAttrAccessGroup]; + // Ignore the access group if running on the iPhone simulator. + // + // Apps that are built for the simulator aren't signed, so there's no keychain access group + // for the simulator to check. This means that all apps can see all keychain items when run + // on the simulator. + // + // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the + // simulator will return -25243 (errSecNoAccessForItem). +#else + [keychainQuery setObject:accessGroup + forKey:(id)kSecAttrAccessGroup]; #endif - } - - // Use the proper search constants, return only the attributes of the first match. - [keychainQuery setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit]; - [keychainQuery setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnAttributes]; - - NSDictionary *tempQuery = [NSDictionary dictionaryWithDictionary:keychainQuery]; - - NSMutableDictionary *outDictionary = nil; - - if (!SecItemCopyMatching((CFDictionaryRef)tempQuery, (CFTypeRef *)&outDictionary) == noErr) - { - // Stick these default values into keychain item if nothing found. - [self resetKeychainItem]; - - // Add the generic attribute and the keychain access group. - [self replaceValue:identifier forKey:(id)kSecAttrGeneric notification:NO]; - //[keychainItemData setObject:identifier forKey:(id)kSecAttrGeneric]; - if (accessGroup != nil) - { + } + + // Use the proper search constants, return only the attributes of the first match. + [keychainQuery setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit]; + [keychainQuery setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnAttributes]; + + NSDictionary *tempQuery = [NSDictionary dictionaryWithDictionary:keychainQuery]; + + NSMutableDictionary *outDictionary = nil; + + if (!SecItemCopyMatching((CFDictionaryRef)tempQuery, (CFTypeRef *)&outDictionary) == noErr) { + // Stick these default values into keychain item if nothing found. + [self resetKeychainItem]; + + // Add the generic attribute and the keychain access group. + [self replaceValue:identifier forKey:(id)kSecAttrGeneric notification:NO]; + //[keychainItemData setObject:identifier forKey:(id)kSecAttrGeneric]; + if (accessGroup != nil) { #if TARGET_IPHONE_SIMULATOR - // Ignore the access group if running on the iPhone simulator. - // - // Apps that are built for the simulator aren't signed, so there's no keychain access group - // for the simulator to check. This means that all apps can see all keychain items when run - // on the simulator. - // - // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the - // simulator will return -25243 (errSecNoAccessForItem). -#else - [keychainItemData setObject:accessGroup forKey:(id)kSecAttrAccessGroup]; + // Ignore the access group if running on the iPhone simulator. + // + // Apps that are built for the simulator aren't signed, so there's no keychain access group + // for the simulator to check. This means that all apps can see all keychain items when run + // on the simulator. + // + // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the + // simulator will return -25243 (errSecNoAccessForItem). +#else + [keychainItemData setObject:accessGroup + forKey:(id)kSecAttrAccessGroup]; #endif - } - } - else - { - // load the saved data from Keychain. - keychainItemData = [self secItemFormatToDictionary:outDictionary]; - } - - [outDictionary release]; -} + } + } else { + // load the saved data from Keychain. + keychainItemData = [self secItemFormatToDictionary:outDictionary]; + } + [outDictionary release]; +} -- (void)setObject:(id)inObject forKey:(id)key +- (void)setObject:(id)inObject forKey:(id)key { - if (inObject == nil) return; - id currentObject = [keychainItemData objectForKey:key]; - if (![currentObject isEqual:inObject]) - { - [keychainItemData setObject:inObject forKey:key]; - [self writeToKeychain]; - } + if (inObject == nil) + return; + id currentObject = [keychainItemData objectForKey:key]; + if (![currentObject isEqual:inObject]) { + [keychainItemData setObject:inObject forKey:key]; + [self writeToKeychain]; + } } - (id)objectForKey:(id)key { - return [keychainItemData objectForKey:key]; + return [keychainItemData objectForKey:key]; } - (void)resetKeychainItem { - OSStatus junk = noErr; - if (!keychainItemData) - { - keychainItemData = [[NSMutableDictionary alloc] init]; - } - else if (keychainItemData) - { - NSMutableDictionary *tempDictionary = [self dictionaryToSecItemFormat:keychainItemData]; - junk = SecItemDelete((CFDictionaryRef)tempDictionary); - NSAssert( junk == noErr || junk == errSecItemNotFound, @"Problem deleting current dictionary." ); - } - - // Default attributes for keychain item. - [keychainItemData setObject:@"" forKey:(id)kSecAttrAccount]; - [keychainItemData setObject:@"" forKey:(id)kSecAttrLabel]; - [keychainItemData setObject:@"" forKey:(id)kSecAttrDescription]; - - // Default data for keychain item. - [keychainItemData setObject:@"" forKey:(id)kSecValueData]; + OSStatus junk = noErr; + if (!keychainItemData) { + keychainItemData = [[NSMutableDictionary alloc] init]; + } else if (keychainItemData) { + NSMutableDictionary *tempDictionary = [self dictionaryToSecItemFormat:keychainItemData]; + junk = SecItemDelete((CFDictionaryRef)tempDictionary); + NSAssert(junk == noErr || junk == errSecItemNotFound, @"Problem deleting current dictionary."); + } + + // Default attributes for keychain item. + [keychainItemData setObject:@"" forKey:(id)kSecAttrAccount]; + [keychainItemData setObject:@"" forKey:(id)kSecAttrLabel]; + [keychainItemData setObject:@"" forKey:(id)kSecAttrDescription]; + + // Default data for keychain item. + [keychainItemData setObject:@"" forKey:(id)kSecValueData]; } - - (NSMutableDictionary *)dictionaryToSecItemFormat:(NSDictionary *)dictionaryToConvert { - // The assumption is that this method will be called with a properly populated dictionary - // containing all the right key/value pairs for a SecItem. - - // Create a dictionary to return populated with the attributes and data. - NSMutableDictionary *returnDictionary = [NSMutableDictionary dictionaryWithDictionary:dictionaryToConvert]; - - // Add the Generic Password keychain item class attribute. - [returnDictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; - - // Convert the NSString to NSData to meet the requirements for the value type kSecValueData. - // This is where to store sensitive data that should be encrypted. - NSString *passwordString = [dictionaryToConvert objectForKey:(id)kSecValueData]; - [returnDictionary setObject:[passwordString dataUsingEncoding:NSUTF8StringEncoding] forKey:(id)kSecValueData]; - - return returnDictionary; + // The assumption is that this method will be called with a properly populated dictionary + // containing all the right key/value pairs for a SecItem. + + // Create a dictionary to return populated with the attributes and data. + NSMutableDictionary *returnDictionary = [NSMutableDictionary dictionaryWithDictionary:dictionaryToConvert]; + + // Add the Generic Password keychain item class attribute. + [returnDictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; + + // Convert the NSString to NSData to meet the requirements for the value type kSecValueData. + // This is where to store sensitive data that should be encrypted. + NSString *passwordString = [dictionaryToConvert objectForKey:(id)kSecValueData]; + [returnDictionary setObject:[passwordString dataUsingEncoding:NSUTF8StringEncoding] forKey:(id)kSecValueData]; + + return returnDictionary; } - (NSMutableDictionary *)secItemFormatToDictionary:(NSDictionary *)dictionaryToConvert { - // The assumption is that this method will be called with a properly populated dictionary - // containing all the right key/value pairs for the UI element. - - // Create a dictionary to return populated with the attributes and data. - NSMutableDictionary *returnDictionary = [NSMutableDictionary dictionaryWithDictionary:dictionaryToConvert]; - - // Add the proper search key and class attribute. - [returnDictionary setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData]; - [returnDictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; - - // Acquire the password data from the attributes. - NSData *passwordData = NULL; - if (SecItemCopyMatching((CFDictionaryRef)returnDictionary, (CFTypeRef *)&passwordData) == noErr) - { - // Remove the search, class, and identifier key/value, we don't need them anymore. - [returnDictionary removeObjectForKey:(id)kSecReturnData]; - - // Add the password to the dictionary, converting from NSData to NSString. - NSString *password = [[[NSString alloc] initWithBytes:[passwordData bytes] length:[passwordData length] - encoding:NSUTF8StringEncoding] autorelease]; - [returnDictionary setObject:password forKey:(id)kSecValueData]; - } - else - { - // Don't do anything if nothing is found. - NSAssert(NO, @"Serious error, no matching item found in the keychain.\n"); - } - - [passwordData release]; - - return returnDictionary; + // The assumption is that this method will be called with a properly populated dictionary + // containing all the right key/value pairs for the UI element. + + // Create a dictionary to return populated with the attributes and data. + NSMutableDictionary *returnDictionary = [NSMutableDictionary dictionaryWithDictionary:dictionaryToConvert]; + + // Add the proper search key and class attribute. + [returnDictionary setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData]; + [returnDictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; + + // Acquire the password data from the attributes. + NSData *passwordData = NULL; + if (SecItemCopyMatching((CFDictionaryRef)returnDictionary, (CFTypeRef *)&passwordData) == noErr) { + // Remove the search, class, and identifier key/value, we don't need them anymore. + [returnDictionary removeObjectForKey:(id)kSecReturnData]; + + // Add the password to the dictionary, converting from NSData to NSString. + NSString *password = [[[NSString alloc] initWithBytes:[passwordData bytes] + length:[passwordData length] + encoding:NSUTF8StringEncoding] autorelease]; + [returnDictionary setObject:password forKey:(id)kSecValueData]; + } else { + // Don't do anything if nothing is found. + NSAssert(NO, @"Serious error, no matching item found in the keychain.\n"); + } + + [passwordData release]; + + return returnDictionary; } - (void)writeToKeychain { - NSDictionary *attributes = NULL; - NSMutableDictionary *updateItem = NULL; - OSStatus result; - - if (SecItemCopyMatching((CFDictionaryRef)keychainQuery, (CFTypeRef *)&attributes) == noErr) - { - // First we need the attributes from the Keychain. - updateItem = [NSMutableDictionary dictionaryWithDictionary:attributes]; - // Second we need to add the appropriate search key/values. - [updateItem setObject:[keychainQuery objectForKey:(id)kSecClass] forKey:(id)kSecClass]; - - // Lastly, we need to set up the updated attribute list being careful to remove the class. - NSMutableDictionary *tempCheck = [self dictionaryToSecItemFormat:keychainItemData]; - [tempCheck removeObjectForKey:(id)kSecClass]; - + NSDictionary *attributes = NULL; + NSMutableDictionary *updateItem = NULL; + OSStatus result; + + if (SecItemCopyMatching((CFDictionaryRef)keychainQuery, (CFTypeRef *)&attributes) == noErr) { + // First we need the attributes from the Keychain. + updateItem = [NSMutableDictionary dictionaryWithDictionary:attributes]; + // Second we need to add the appropriate search key/values. + [updateItem setObject:[keychainQuery objectForKey:(id)kSecClass] forKey:(id)kSecClass]; + + // Lastly, we need to set up the updated attribute list being careful to remove the class. + NSMutableDictionary *tempCheck = [self dictionaryToSecItemFormat:keychainItemData]; + [tempCheck removeObjectForKey:(id)kSecClass]; + #if TARGET_IPHONE_SIMULATOR - // Remove the access group if running on the iPhone simulator. - // - // Apps that are built for the simulator aren't signed, so there's no keychain access group - // for the simulator to check. This means that all apps can see all keychain items when run - // on the simulator. - // - // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the - // simulator will return -25243 (errSecNoAccessForItem). - // - // The access group attribute will be included in items returned by SecItemCopyMatching, - // which is why we need to remove it before updating the item. - [tempCheck removeObjectForKey:(id)kSecAttrAccessGroup]; + // Remove the access group if running on the iPhone simulator. + // + // Apps that are built for the simulator aren't signed, so there's no keychain access group + // for the simulator to check. This means that all apps can see all keychain items when run + // on the simulator. + // + // If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the + // simulator will return -25243 (errSecNoAccessForItem). + // + // The access group attribute will be included in items returned by SecItemCopyMatching, + // which is why we need to remove it before updating the item. + [tempCheck removeObjectForKey:(id)kSecAttrAccessGroup]; #endif - - // An implicit assumption is that you can only update a single item at a time. - - result = SecItemUpdate((CFDictionaryRef)updateItem, (CFDictionaryRef)tempCheck); - NSAssert( result == noErr, @"Couldn't update the Keychain Item." ); - } - else - { - // No previous item found; add the new one. - result = SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL); - NSAssert( result == noErr, @"Couldn't add the Keychain Item." ); - } + + // An implicit assumption is that you can only update a single item at a time. + + result = SecItemUpdate((CFDictionaryRef)updateItem, (CFDictionaryRef)tempCheck); + NSAssert(result == noErr, @"Couldn't update the Keychain Item."); + } else { + // No previous item found; add the new one. + result = SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL); + NSAssert(result == noErr, @"Couldn't add the Keychain Item."); + } } @end - diff --git a/ios/Classes/TiCryptoModule.h b/ios/Classes/TiCryptoModule.h index 486f1aa..7606bb6 100644 --- a/ios/Classes/TiCryptoModule.h +++ b/ios/Classes/TiCryptoModule.h @@ -8,24 +8,23 @@ #import enum { - kCCError = -1 + kCCError = -1 }; typedef enum { - kDataTypeBlob = 0, - kDataTypeHexString = 1, - kDataTypeBase64String = 2 + kDataTypeBlob = 0, + kDataTypeHexString = 1, + kDataTypeBase64String = 2 } cryptoDataType; -extern NSString * const kDataTypeBlobName; -extern NSString * const kDataTypeHexStringName; -extern NSString * const kDataTypeBase64StringName; +extern NSString *const kDataTypeBlobName; +extern NSString *const kDataTypeHexStringName; +extern NSString *const kDataTypeBase64StringName; @interface TiCryptoModule : TiModule +- (NSString *)decodeData:(id)args; --(NSString*)decodeData:(id)args; - --(NSNumber*)encodeData:(id)args; +- (NSNumber *)encodeData:(id)args; @end diff --git a/ios/Classes/TiCryptoModule.m b/ios/Classes/TiCryptoModule.m index f61f55f..91e676f 100644 --- a/ios/Classes/TiCryptoModule.m +++ b/ios/Classes/TiCryptoModule.m @@ -16,208 +16,208 @@ @implementation TiCryptoModule #pragma mark Internal // this is generated for your module, please do not change it --(id)moduleGUID +- (id)moduleGUID { - return @"5041eaca-a895-4229-a44b-de2f582c9133"; + return @"5041eaca-a895-4229-a44b-de2f582c9133"; } // this is generated for your module, please do not change it --(NSString*)moduleId +- (NSString *)moduleId { - return @"ti.crypto"; + return @"ti.crypto"; } #pragma mark Lifecycle --(void)startup +- (void)startup { - // this method is called when the module is first loaded - // you *must* call the superclass - [super startup]; - - NSLog(@"[INFO] %@ loaded",self); + // this method is called when the module is first loaded + // you *must* call the superclass + [super startup]; + + NSLog(@"[INFO] %@ loaded", self); } --(void)shutdown:(id)sender +- (void)shutdown:(id)sender { - // this method is called when the module is being unloaded - // typically this is during shutdown. make sure you don't do too - // much processing here or the app will be quit forceably - - // you *must* call the superclass - [super shutdown:sender]; + // this method is called when the module is being unloaded + // typically this is during shutdown. make sure you don't do too + // much processing here or the app will be quit forceably + + // you *must* call the superclass + [super shutdown:sender]; } -#pragma mark Cleanup +#pragma mark Cleanup --(void)dealloc +- (void)dealloc { - // release any resources that have been retained by the module - [super dealloc]; + // release any resources that have been retained by the module + [super dealloc]; } #pragma mark Internal Memory Management --(void)didReceiveMemoryWarning:(NSNotification*)notification +- (void)didReceiveMemoryWarning:(NSNotification *)notification { - // optionally release any resources that can be dynamically - // reloaded once memory is available - such as caches - [super didReceiveMemoryWarning:notification]; + // optionally release any resources that can be dynamically + // reloaded once memory is available - such as caches + [super didReceiveMemoryWarning:notification]; } #pragma mark Public Methods -NSString * const kDataTypeBlobName = @"blob"; -NSString * const kDataTypeHexStringName = @"hexstring"; -NSString * const kDataTypeBase64StringName = @"base64string"; +NSString *const kDataTypeBlobName = @"blob"; +NSString *const kDataTypeHexStringName = @"hexstring"; +NSString *const kDataTypeBase64StringName = @"base64string"; -static NSDictionary* dataTypeMap = nil; +static NSDictionary *dataTypeMap = nil; -+(cryptoDataType)constantToDataType:(NSString*)type ++ (cryptoDataType)constantToDataType:(NSString *)type { - if (dataTypeMap == nil) { - dataTypeMap = [[NSDictionary alloc] initWithObjectsAndKeys: - @(kDataTypeBlob),kDataTypeBlobName, - @(kDataTypeHexString),kDataTypeHexStringName, - @(kDataTypeBase64String),kDataTypeBase64StringName, - nil]; - } - return [[dataTypeMap valueForKey:type] intValue]; + if (dataTypeMap == nil) { + dataTypeMap = [[NSDictionary alloc] initWithObjectsAndKeys: + @(kDataTypeBlob), kDataTypeBlobName, + @(kDataTypeHexString), kDataTypeHexStringName, + @(kDataTypeBase64String), kDataTypeBase64StringName, + nil]; + } + return [[dataTypeMap valueForKey:type] intValue]; } --(NSString*)decodeData:(id)args +- (NSString *)decodeData:(id)args { - ENSURE_SINGLE_ARG(args,NSDictionary); - - NSString* type; - TiBuffer* source; - id result = nil; - - ENSURE_ARG_FOR_KEY(type, args, @"type", NSString); - ENSURE_ARG_FOR_KEY(source, args, @"source", TiBuffer); - - switch ([TiCryptoModule constantToDataType:type]) { - case kDataTypeBase64String: - result = [TiCryptoUtils base64encode:source]; - break; - case kDataTypeHexString: - result = [TiCryptoUtils convertToHex:source]; - break; - default: - [self throwException:[NSString stringWithFormat:@"Invalid type identifier '%@'",type] - subreason:nil - location:CODELOCATION]; - break; - } - - return result; + ENSURE_SINGLE_ARG(args, NSDictionary); + + NSString *type; + TiBuffer *source; + id result = nil; + + ENSURE_ARG_FOR_KEY(type, args, @"type", NSString); + ENSURE_ARG_FOR_KEY(source, args, @"source", TiBuffer); + + switch ([TiCryptoModule constantToDataType:type]) { + case kDataTypeBase64String: + result = [TiCryptoUtils base64encode:source]; + break; + case kDataTypeHexString: + result = [TiCryptoUtils convertToHex:source]; + break; + default: + [self throwException:[NSString stringWithFormat:@"Invalid type identifier '%@'", type] + subreason:nil + location:CODELOCATION]; + break; + } + + return result; } --(NSNumber*)encodeData:(id)args +- (NSNumber *)encodeData:(id)args { - ENSURE_SINGLE_ARG(args,NSDictionary); - - NSString* type; - id source; - TiBuffer* dest = nil; - int destPosition; - BOOL hasDestPosition; - NSData *data; - - ENSURE_ARG_FOR_KEY(type, args, @"type", NSString); - ENSURE_ARG_FOR_KEY(source, args, @"source", NSObject); - ENSURE_ARG_FOR_KEY(dest, args, @"dest", TiBuffer); - ENSURE_INT_OR_NIL_FOR_KEY(destPosition, args, @"destPosition", hasDestPosition); - - destPosition = (hasDestPosition) ? destPosition : 0; - - switch ([TiCryptoModule constantToDataType:type]) { - case kDataTypeBlob: - ENSURE_TYPE(source,TiBlob); - data = [source data]; - break; - case kDataTypeHexString: - ENSURE_TYPE(source,NSString); - data = [TiCryptoUtils convertFromHex:source]; - break; - case kDataTypeBase64String: - ENSURE_TYPE(source,NSString); - data = [TiCryptoUtils base64decode:source]; - break; - default: - [self throwException:[NSString stringWithFormat:@"Invalid type identifier '%@'",type] - subreason:nil - location:CODELOCATION]; - break; - } - - // Verify that the offset is within range - NSUInteger destLength = [[dest data] length]; - if (destPosition >= destLength) { - NSLog(@"[ERROR] Destination position of %d is past end of buffer. Buffer size is %d.", destPosition, destLength); - return @(BAD_DEST_OFFSET); - } - - // Verify that the destination can hold the result - NSUInteger srcLength = [data length]; - NSUInteger neededLength = destPosition + srcLength; - if (neededLength > destLength) { - NSLog(@"[ERROR] Destination buffer size of %d is too small. Needed %d.", destLength, neededLength); - return @(TOO_SMALL); - } - - void* bufferBytes = [[dest data] mutableBytes]; - const void* srcBytes = [data bytes]; - - memcpy(bufferBytes + destPosition, srcBytes, srcLength); - - return @(destPosition + srcLength); + ENSURE_SINGLE_ARG(args, NSDictionary); + + NSString *type; + id source; + TiBuffer *dest = nil; + int destPosition; + BOOL hasDestPosition; + NSData *data; + + ENSURE_ARG_FOR_KEY(type, args, @"type", NSString); + ENSURE_ARG_FOR_KEY(source, args, @"source", NSObject); + ENSURE_ARG_FOR_KEY(dest, args, @"dest", TiBuffer); + ENSURE_INT_OR_NIL_FOR_KEY(destPosition, args, @"destPosition", hasDestPosition); + + destPosition = (hasDestPosition) ? destPosition : 0; + + switch ([TiCryptoModule constantToDataType:type]) { + case kDataTypeBlob: + ENSURE_TYPE(source, TiBlob); + data = [source data]; + break; + case kDataTypeHexString: + ENSURE_TYPE(source, NSString); + data = [TiCryptoUtils convertFromHex:source]; + break; + case kDataTypeBase64String: + ENSURE_TYPE(source, NSString); + data = [TiCryptoUtils base64decode:source]; + break; + default: + [self throwException:[NSString stringWithFormat:@"Invalid type identifier '%@'", type] + subreason:nil + location:CODELOCATION]; + break; + } + + // Verify that the offset is within range + NSUInteger destLength = [[dest data] length]; + if (destPosition >= destLength) { + NSLog(@"[ERROR] Destination position of %d is past end of buffer. Buffer size is %d.", destPosition, destLength); + return @(BAD_DEST_OFFSET); + } + + // Verify that the destination can hold the result + NSUInteger srcLength = [data length]; + NSUInteger neededLength = destPosition + srcLength; + if (neededLength > destLength) { + NSLog(@"[ERROR] Destination buffer size of %d is too small. Needed %d.", destLength, neededLength); + return @(TOO_SMALL); + } + + void *bufferBytes = [[dest data] mutableBytes]; + const void *srcBytes = [data bytes]; + + memcpy(bufferBytes + destPosition, srcBytes, srcLength); + + return @(destPosition + srcLength); } #pragma mark Constants -MAKE_SYSTEM_PROP(STATUS_SUCCESS,kCCSuccess) -MAKE_SYSTEM_PROP(STATUS_ERROR,kCCError) -MAKE_SYSTEM_PROP(STATUS_PARAMERROR,kCCParamError) -MAKE_SYSTEM_PROP(STATUS_BUFFERTOOSMALL,kCCBufferTooSmall) -MAKE_SYSTEM_PROP(STATUS_MEMORYFAILURE,kCCMemoryFailure) -MAKE_SYSTEM_PROP(STATUS_ALIGNMENTERROR,kCCAlignmentError) -MAKE_SYSTEM_PROP(STATUS_DECODEERROR,kCCDecodeError) -MAKE_SYSTEM_PROP(STATUS_UNIMPLEMENTED,kCCUnimplemented) - -MAKE_SYSTEM_PROP(ENCRYPT,kCCEncrypt) -MAKE_SYSTEM_PROP(DECRYPT,kCCDecrypt) - -MAKE_SYSTEM_PROP(ALGORITHM_AES128,kCCAlgorithmAES128) -MAKE_SYSTEM_PROP(ALGORITHM_DES,kCCAlgorithmDES) -MAKE_SYSTEM_PROP(ALGORITHM_3DES,kCCAlgorithm3DES) -MAKE_SYSTEM_PROP(ALGORITHM_CAST,kCCAlgorithmCAST) -MAKE_SYSTEM_PROP(ALGORITHM_RC4,kCCAlgorithmRC4) -MAKE_SYSTEM_PROP(ALGORITHM_RC2,kCCAlgorithmRC2) - -MAKE_SYSTEM_PROP(OPTION_PKCS7PADDING,kCCOptionPKCS7Padding) -MAKE_SYSTEM_PROP(OPTION_ECBMODE,kCCOptionECBMode) - -MAKE_SYSTEM_PROP(KEYSIZE_AES128,kCCKeySizeAES128) -MAKE_SYSTEM_PROP(KEYSIZE_AES192,kCCKeySizeAES192) -MAKE_SYSTEM_PROP(KEYSIZE_AES256,kCCKeySizeAES256) -MAKE_SYSTEM_PROP(KEYSIZE_DES,kCCKeySizeDES) -MAKE_SYSTEM_PROP(KEYSIZE_3DES,kCCKeySize3DES) -MAKE_SYSTEM_PROP(KEYSIZE_MINCAST,kCCKeySizeMinCAST) -MAKE_SYSTEM_PROP(KEYSIZE_MAXCAST,kCCKeySizeMaxCAST) -MAKE_SYSTEM_PROP(KEYSIZE_MINRC4,kCCKeySizeMinRC4) -MAKE_SYSTEM_PROP(KEYSIZE_MAXRC4,kCCKeySizeMaxRC4) -MAKE_SYSTEM_PROP(KEYSIZE_MINRC2,kCCKeySizeMinRC2) -MAKE_SYSTEM_PROP(KEYSIZE_MAXRC2,kCCKeySizeMaxRC2) - -MAKE_SYSTEM_PROP(BLOCKSIZE_AES128,kCCBlockSizeAES128) -MAKE_SYSTEM_PROP(BLOCKSIZE_DES,kCCBlockSizeDES) -MAKE_SYSTEM_PROP(BLOCKSIZE_3DES,kCCBlockSize3DES) -MAKE_SYSTEM_PROP(BLOCKSIZE_CAST,kCCBlockSizeCAST) -MAKE_SYSTEM_PROP(BLOCKSIZE_RC2,kCCBlockSizeRC2) - -MAKE_SYSTEM_STR(TYPE_BLOB,kDataTypeBlobName) -MAKE_SYSTEM_STR(TYPE_HEXSTRING,kDataTypeHexStringName) -MAKE_SYSTEM_STR(TYPE_BASE64STRING,kDataTypeBase64StringName) +MAKE_SYSTEM_PROP(STATUS_SUCCESS, kCCSuccess) +MAKE_SYSTEM_PROP(STATUS_ERROR, kCCError) +MAKE_SYSTEM_PROP(STATUS_PARAMERROR, kCCParamError) +MAKE_SYSTEM_PROP(STATUS_BUFFERTOOSMALL, kCCBufferTooSmall) +MAKE_SYSTEM_PROP(STATUS_MEMORYFAILURE, kCCMemoryFailure) +MAKE_SYSTEM_PROP(STATUS_ALIGNMENTERROR, kCCAlignmentError) +MAKE_SYSTEM_PROP(STATUS_DECODEERROR, kCCDecodeError) +MAKE_SYSTEM_PROP(STATUS_UNIMPLEMENTED, kCCUnimplemented) + +MAKE_SYSTEM_PROP(ENCRYPT, kCCEncrypt) +MAKE_SYSTEM_PROP(DECRYPT, kCCDecrypt) + +MAKE_SYSTEM_PROP(ALGORITHM_AES128, kCCAlgorithmAES128) +MAKE_SYSTEM_PROP(ALGORITHM_DES, kCCAlgorithmDES) +MAKE_SYSTEM_PROP(ALGORITHM_3DES, kCCAlgorithm3DES) +MAKE_SYSTEM_PROP(ALGORITHM_CAST, kCCAlgorithmCAST) +MAKE_SYSTEM_PROP(ALGORITHM_RC4, kCCAlgorithmRC4) +MAKE_SYSTEM_PROP(ALGORITHM_RC2, kCCAlgorithmRC2) + +MAKE_SYSTEM_PROP(OPTION_PKCS7PADDING, kCCOptionPKCS7Padding) +MAKE_SYSTEM_PROP(OPTION_ECBMODE, kCCOptionECBMode) + +MAKE_SYSTEM_PROP(KEYSIZE_AES128, kCCKeySizeAES128) +MAKE_SYSTEM_PROP(KEYSIZE_AES192, kCCKeySizeAES192) +MAKE_SYSTEM_PROP(KEYSIZE_AES256, kCCKeySizeAES256) +MAKE_SYSTEM_PROP(KEYSIZE_DES, kCCKeySizeDES) +MAKE_SYSTEM_PROP(KEYSIZE_3DES, kCCKeySize3DES) +MAKE_SYSTEM_PROP(KEYSIZE_MINCAST, kCCKeySizeMinCAST) +MAKE_SYSTEM_PROP(KEYSIZE_MAXCAST, kCCKeySizeMaxCAST) +MAKE_SYSTEM_PROP(KEYSIZE_MINRC4, kCCKeySizeMinRC4) +MAKE_SYSTEM_PROP(KEYSIZE_MAXRC4, kCCKeySizeMaxRC4) +MAKE_SYSTEM_PROP(KEYSIZE_MINRC2, kCCKeySizeMinRC2) +MAKE_SYSTEM_PROP(KEYSIZE_MAXRC2, kCCKeySizeMaxRC2) + +MAKE_SYSTEM_PROP(BLOCKSIZE_AES128, kCCBlockSizeAES128) +MAKE_SYSTEM_PROP(BLOCKSIZE_DES, kCCBlockSizeDES) +MAKE_SYSTEM_PROP(BLOCKSIZE_3DES, kCCBlockSize3DES) +MAKE_SYSTEM_PROP(BLOCKSIZE_CAST, kCCBlockSizeCAST) +MAKE_SYSTEM_PROP(BLOCKSIZE_RC2, kCCBlockSizeRC2) + +MAKE_SYSTEM_STR(TYPE_BLOB, kDataTypeBlobName) +MAKE_SYSTEM_STR(TYPE_HEXSTRING, kDataTypeHexStringName) +MAKE_SYSTEM_STR(TYPE_BASE64STRING, kDataTypeBase64StringName) @end diff --git a/ios/Classes/TiCryptoModuleAssets.h b/ios/Classes/TiCryptoModuleAssets.h index 7c968db..b27a234 100644 --- a/ios/Classes/TiCryptoModuleAssets.h +++ b/ios/Classes/TiCryptoModuleAssets.h @@ -2,8 +2,7 @@ * This is a generated file. Do not edit or your changes will be lost */ -@interface TiCryptoModuleAssets : NSObject -{ +@interface TiCryptoModuleAssets : NSObject { } -- (NSData*) moduleAsset; +- (NSData *)moduleAsset; @end diff --git a/ios/Classes/TiCryptoModuleAssets.m b/ios/Classes/TiCryptoModuleAssets.m index c196a3b..a406050 100644 --- a/ios/Classes/TiCryptoModuleAssets.m +++ b/ios/Classes/TiCryptoModuleAssets.m @@ -3,13 +3,13 @@ */ #import "TiCryptoModuleAssets.h" -extern NSData * dataWithHexString (NSString * hexString); +extern NSData *dataWithHexString(NSString *hexString); @implementation TiCryptoModuleAssets -- (NSData*) moduleAsset +- (NSData *)moduleAsset { - return nil; + return nil; } @end diff --git a/ios/Classes/TiCryptoUtils.h b/ios/Classes/TiCryptoUtils.h index f7f064e..d123fa4 100644 --- a/ios/Classes/TiCryptoUtils.h +++ b/ios/Classes/TiCryptoUtils.h @@ -9,9 +9,9 @@ @interface TiCryptoUtils : NSObject { } -+(NSString*)convertToHex:(TiBuffer*)buffer; -+(NSMutableData*)convertFromHex:(NSString*)value; -+(NSString*)base64encode:(TiBuffer*)buffer; -+(NSMutableData*)base64decode:(NSString*)str; ++ (NSString *)convertToHex:(TiBuffer *)buffer; ++ (NSMutableData *)convertFromHex:(NSString *)value; ++ (NSString *)base64encode:(TiBuffer *)buffer; ++ (NSMutableData *)base64decode:(NSString *)str; @end diff --git a/ios/Classes/TiCryptoUtils.m b/ios/Classes/TiCryptoUtils.m index 60bb932..cdce9c1 100644 --- a/ios/Classes/TiCryptoUtils.m +++ b/ios/Classes/TiCryptoUtils.m @@ -10,79 +10,79 @@ @implementation TiCryptoUtils -+(NSString*)convertToHex:(TiBuffer*)buffer ++ (NSString *)convertToHex:(TiBuffer *)buffer { - const char *data = [[buffer data] bytes]; - size_t len = [[buffer data] length]; - - NSMutableString* encoded = [[NSMutableString alloc] initWithCapacity:len*2]; - for (int i=0; i < len; i++) { - [encoded appendFormat:@"%02x",data[i]]; - } - NSString* value = [encoded lowercaseString]; - [encoded release]; - - return value; + const char *data = [[buffer data] bytes]; + size_t len = [[buffer data] length]; + + NSMutableString *encoded = [[NSMutableString alloc] initWithCapacity:len * 2]; + for (int i = 0; i < len; i++) { + [encoded appendFormat:@"%02x", data[i]]; + } + NSString *value = [encoded lowercaseString]; + [encoded release]; + + return value; } -+(NSMutableData*)convertFromHex:(NSString*)value ++ (NSMutableData *)convertFromHex:(NSString *)value { - // This implementation supports either a straight hexadecimal string or one - // that is formatted with spaces between each hexadecimal byte - NSString* valueToConvert = [value stringByReplacingOccurrencesOfString:@" " withString:@""]; - NSMutableData* data = [[[NSMutableData alloc] initWithCapacity:(valueToConvert.length / 2)] autorelease]; - - unsigned char whole_byte; - char byte_chars[3]; - byte_chars[2] = '\0'; - int i; - NSUInteger len = [valueToConvert length] / 2; - for (i=0; i < len; i++) { - byte_chars[0] = [valueToConvert characterAtIndex:i*2]; - byte_chars[1] = [valueToConvert characterAtIndex:i*2+1]; - whole_byte = strtol(byte_chars, NULL, 16); - [data appendBytes:&whole_byte length:1]; - } - - return data; + // This implementation supports either a straight hexadecimal string or one + // that is formatted with spaces between each hexadecimal byte + NSString *valueToConvert = [value stringByReplacingOccurrencesOfString:@" " withString:@""]; + NSMutableData *data = [[[NSMutableData alloc] initWithCapacity:(valueToConvert.length / 2)] autorelease]; + + unsigned char whole_byte; + char byte_chars[3]; + byte_chars[2] = '\0'; + int i; + NSUInteger len = [valueToConvert length] / 2; + for (i = 0; i < len; i++) { + byte_chars[0] = [valueToConvert characterAtIndex:i * 2]; + byte_chars[1] = [valueToConvert characterAtIndex:i * 2 + 1]; + whole_byte = strtol(byte_chars, NULL, 16); + [data appendBytes:&whole_byte length:1]; + } + + return data; } -+(NSString*)base64encode:(TiBuffer*)buffer ++ (NSString *)base64encode:(TiBuffer *)buffer { - NSString *str = nil; - const char *data = [[buffer data] bytes]; - size_t len = [[buffer data] length]; - - size_t outsize = TiCryptoEstimateBas64EncodedDataSize(len); - char *base64Result = malloc(sizeof(char)*outsize); - size_t theResultLength = outsize; - - bool result = TiCryptoBase64EncodeData(data, len, base64Result, &theResultLength); - if (result) { - str = [[[NSString alloc] initWithBytes:base64Result length:theResultLength encoding:NSUTF8StringEncoding] autorelease]; - } - free(base64Result); - - return str; + NSString *str = nil; + const char *data = [[buffer data] bytes]; + size_t len = [[buffer data] length]; + + size_t outsize = TiCryptoEstimateBas64EncodedDataSize(len); + char *base64Result = malloc(sizeof(char) * outsize); + size_t theResultLength = outsize; + + bool result = TiCryptoBase64EncodeData(data, len, base64Result, &theResultLength); + if (result) { + str = [[[NSString alloc] initWithBytes:base64Result length:theResultLength encoding:NSUTF8StringEncoding] autorelease]; + } + free(base64Result); + + return str; } -+(NSMutableData*)base64decode:(NSString*)str ++ (NSMutableData *)base64decode:(NSString *)str { - NSMutableData *theData = nil; - const char *data = [str UTF8String]; - size_t len = [str length]; - - size_t outsize = TiCryptoEstimateBas64DecodedDataSize(len); - char *base64Result = malloc(sizeof(char)*outsize); - size_t theResultLength = outsize; - - bool result = TiCryptoBase64DecodeData(data, len, base64Result, &theResultLength); - if (result) { - theData = [NSMutableData dataWithBytes:base64Result length:theResultLength]; - } - free(base64Result); - - return theData; + NSMutableData *theData = nil; + const char *data = [str UTF8String]; + size_t len = [str length]; + + size_t outsize = TiCryptoEstimateBas64DecodedDataSize(len); + char *base64Result = malloc(sizeof(char) * outsize); + size_t theResultLength = outsize; + + bool result = TiCryptoBase64DecodeData(data, len, base64Result, &theResultLength); + if (result) { + theData = [NSMutableData dataWithBytes:base64Result length:theResultLength]; + } + free(base64Result); + + return theData; } @end From 3ccd738548381c1a626221f6f888671782b1b443 Mon Sep 17 00:00:00 2001 From: hansemannn Date: Wed, 15 Aug 2018 11:42:25 +0200 Subject: [PATCH 3/5] chore: lint all Android sources --- android/.clang-format | 26 +++++++++ android/src/ti/crypto/CryptoModule.java | 27 ++++++---- android/src/ti/crypto/CryptorProxy.java | 71 ++++++++++++++++--------- android/src/ti/crypto/utility/Hex.java | 12 +++-- 4 files changed, 99 insertions(+), 37 deletions(-) create mode 100644 android/.clang-format diff --git a/android/.clang-format b/android/.clang-format new file mode 100644 index 0000000..3e6a508 --- /dev/null +++ b/android/.clang-format @@ -0,0 +1,26 @@ +--- +Language: Java +AccessModifierOffset: -4 +AllowShortBlocksOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +# class, constructor, method should be next line +BreakBeforeBraces: Linux +# Keep '=' at end of line when wrapping, but move things like '&&', '||' to beginning of newline +BreakBeforeBinaryOperators: NonAssignment +# FIXME: break for brace after synchronized block, anonymous class declarations +BreakAfterJavaFieldAnnotations: true +ColumnLimit: 120 +IndentCaseLabels: true +IndentWidth: 4 +MaxEmptyLinesToKeep: 1 +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpacesInParentheses: false +TabWidth: 4 +UseTab: ForContinuationAndIndentation +SpaceAfterCStyleCast: true +# Spaces inside {} for array literals, i.e. "new Object[] { args }" +Cpp11BracedListStyle: false +ReflowComments: false diff --git a/android/src/ti/crypto/CryptoModule.java b/android/src/ti/crypto/CryptoModule.java index 874a552..331b671 100644 --- a/android/src/ti/crypto/CryptoModule.java +++ b/android/src/ti/crypto/CryptoModule.java @@ -19,23 +19,29 @@ import org.appcelerator.kroll.common.Log; @Kroll.module(name = "Crypto", id = "ti.crypto") -public class CryptoModule extends KrollModule { +public class CryptoModule extends KrollModule +{ private static final String LCAT = "CryptoModule"; - static { + static + { Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider()); } - public CryptoModule() { + public CryptoModule() + { super(); } // Methods @Kroll.method - public int encodeData(@SuppressWarnings("rawtypes") HashMap args) { + public int encodeData(@SuppressWarnings("rawtypes") HashMap args) + { // Validate and grab the arguments we need. if (args == null || !args.containsKey("type") || !args.containsKey("source") || !args.containsKey("dest")) { - Log.e(LCAT, "Not all required parameters and keys provided to encodeData! Please check the documentation and your usage."); + Log.e( + LCAT, + "Not all required parameters and keys provided to encodeData! Please check the documentation and your usage."); return STATUS_PARAMERROR; } @SuppressWarnings("unchecked") @@ -69,7 +75,8 @@ public int encodeData(@SuppressWarnings("rawtypes") HashMap args) { // Verify that the offset is within range. int destLength = dest.getLength(); if (destPosition >= destLength) { - Log.e(LCAT, "Destination position of " + destPosition + " is past end of buffer. Buffer size is " + destLength + "."); + Log.e(LCAT, "Destination position of " + destPosition + " is past end of buffer. Buffer size is " + + destLength + "."); return STATUS_BUFFERTOOSMALL; } @@ -87,10 +94,13 @@ public int encodeData(@SuppressWarnings("rawtypes") HashMap args) { } @Kroll.method - public String decodeData(@SuppressWarnings("rawtypes") HashMap args) { + public String decodeData(@SuppressWarnings("rawtypes") HashMap args) + { // Validate and grab the arguments we need. if (args == null || !args.containsKey("type") || !args.containsKey("source")) { - Log.e(LCAT, "Not all required parameters and keys provided to decodeData! Please check the documentation and your usage."); + Log.e( + LCAT, + "Not all required parameters and keys provided to decodeData! Please check the documentation and your usage."); return null; } @SuppressWarnings("unchecked") @@ -201,5 +211,4 @@ public String decodeData(@SuppressWarnings("rawtypes") HashMap args) { public static final String TYPE_HEXSTRING = "hexstring"; @Kroll.constant public static final String TYPE_BASE64STRING = "base64string"; - } diff --git a/android/src/ti/crypto/CryptorProxy.java b/android/src/ti/crypto/CryptorProxy.java index beabe07..2ecc806 100644 --- a/android/src/ti/crypto/CryptorProxy.java +++ b/android/src/ti/crypto/CryptorProxy.java @@ -25,15 +25,17 @@ import ti.modules.titanium.BufferProxy; import android.util.Log; -@Kroll.proxy(creatableInModule = CryptoModule.class, propertyAccessors = { "resizeBuffer", "operation", "algorithm", "options", "key", - "initializationVector" }) -public class CryptorProxy extends KrollProxy { +@Kroll.proxy(creatableInModule = CryptoModule.class, + propertyAccessors = { "resizeBuffer", "operation", "algorithm", "options", "key", "initializationVector" }) +public class CryptorProxy extends KrollProxy +{ private static final String LCAT = "CryptoModule"; private PaddedBufferedBlockCipher _encryptCipher; private PaddedBufferedBlockCipher _decryptCipher; - private class CryptOptions { + private class CryptOptions + { // Configuration Options public boolean resizeBuffer; public int operation; @@ -48,24 +50,30 @@ private class CryptOptions { public BufferProxy dataOut; public int dataOutLength; - public byte[] getBytesIn() { + public byte[] getBytesIn() + { return dataIn.getBuffer(); } - public int getDataInLength() { + public int getDataInLength() + { return dataInLength > 0 ? dataInLength : dataIn.getLength(); } - public int getDataOutLength() { + public int getDataOutLength() + { return dataOutLength > 0 ? dataOutLength : dataOut.getLength(); } - public boolean isEncrypt() { + public boolean isEncrypt() + { return operation == CryptoModule.ENCRYPT; } } - private CryptOptions prepareCryptOptions(BufferProxy dataIn, int dataInLength, BufferProxy dataOut, int dataOutLength) { + private CryptOptions prepareCryptOptions(BufferProxy dataIn, int dataInLength, BufferProxy dataOut, + int dataOutLength) + { CryptOptions o = new CryptOptions(); KrollDict dict = this.getProperties(); @@ -74,7 +82,8 @@ private CryptOptions prepareCryptOptions(BufferProxy dataIn, int dataInLength, B o.algorithm = dict.optInt("algorithm", CryptoModule.ALGORITHM_AES128); o.options = dict.optInt("options", 0); o.key = dict.containsKey("key") ? ((BufferProxy) dict.get("key")).getBuffer() : null; - o.iv = dict.containsKey("initializationVector") ? ((BufferProxy) dict.get("initializationVector")).getBuffer() : null; + o.iv = dict.containsKey("initializationVector") ? ((BufferProxy) dict.get("initializationVector")).getBuffer() + : null; o.dataIn = dataIn; o.dataInLength = dataInLength > 0 || dataIn == null ? dataInLength : dataIn.getLength(); @@ -84,7 +93,8 @@ private CryptOptions prepareCryptOptions(BufferProxy dataIn, int dataInLength, B return o; } - private void logBytes(String id, byte[] arr) { + private void logBytes(String id, byte[] arr) + { StringBuffer out = new StringBuffer(); if (arr == null) { out.append("{{ null }}"); @@ -100,7 +110,8 @@ private void logBytes(String id, byte[] arr) { Log.i(LCAT, id + ": " + out.toString()); } - private PaddedBufferedBlockCipher createCipher(CryptOptions o) { + private PaddedBufferedBlockCipher createCipher(CryptOptions o) + { // Start off by figuring out what engine to use. // (This will influence if we can use a block cipher or a stream cipher.) BlockCipher bEngine; @@ -166,7 +177,8 @@ private PaddedBufferedBlockCipher createCipher(CryptOptions o) { return cipher; } - private PaddedBufferedBlockCipher getCipher(CryptOptions o) { + private PaddedBufferedBlockCipher getCipher(CryptOptions o) + { if (o.isEncrypt()) { if (_encryptCipher == null) _encryptCipher = createCipher(o); @@ -178,7 +190,8 @@ private PaddedBufferedBlockCipher getCipher(CryptOptions o) { } } - private int crypt(CryptOptions o) throws Exception { + private int crypt(CryptOptions o) throws Exception + { // Get our cipher. PaddedBufferedBlockCipher cipher = getCipher(o); if (cipher == null) @@ -200,8 +213,10 @@ private int crypt(CryptOptions o) throws Exception { } @Kroll.method - public int encrypt(BufferProxy dataIn, @Kroll.argument(optional = true) int dataInLength, @Kroll.argument(optional = true) BufferProxy dataOut, - @Kroll.argument(optional = true) int dataOutLength) { + public int encrypt(BufferProxy dataIn, @Kroll.argument(optional = true) int dataInLength, + @Kroll.argument(optional = true) BufferProxy dataOut, + @Kroll.argument(optional = true) int dataOutLength) + { try { CryptOptions o = prepareCryptOptions(dataIn, dataInLength, dataOut, dataOutLength); o.operation = CryptoModule.ENCRYPT; @@ -215,8 +230,10 @@ public int encrypt(BufferProxy dataIn, @Kroll.argument(optional = true) int data } @Kroll.method - public int decrypt(BufferProxy dataIn, @Kroll.argument(optional = true) int dataInLength, @Kroll.argument(optional = true) BufferProxy dataOut, - @Kroll.argument(optional = true) int dataOutLength) { + public int decrypt(BufferProxy dataIn, @Kroll.argument(optional = true) int dataInLength, + @Kroll.argument(optional = true) BufferProxy dataOut, + @Kroll.argument(optional = true) int dataOutLength) + { try { CryptOptions o = prepareCryptOptions(dataIn, dataInLength, dataOut, dataOutLength); o.operation = CryptoModule.DECRYPT; @@ -230,7 +247,8 @@ public int decrypt(BufferProxy dataIn, @Kroll.argument(optional = true) int data } @Kroll.method - public int getOutputLength(int dataInLength, boolean isFinal) { + public int getOutputLength(int dataInLength, boolean isFinal) + { if (dataInLength < 0) { dataInLength = 0; } @@ -240,8 +258,10 @@ public int getOutputLength(int dataInLength, boolean isFinal) { } @Kroll.method - public int update(BufferProxy dataIn, @Kroll.argument(optional = true) int dataInLength, @Kroll.argument(optional = true) BufferProxy dataOut, - @Kroll.argument(optional = true) int dataOutLength) { + public int update(BufferProxy dataIn, @Kroll.argument(optional = true) int dataInLength, + @Kroll.argument(optional = true) BufferProxy dataOut, + @Kroll.argument(optional = true) int dataOutLength) + { try { // Get our cipher. CryptOptions o = prepareCryptOptions(dataIn, dataInLength, dataOut, dataOutLength); @@ -268,7 +288,8 @@ public int update(BufferProxy dataIn, @Kroll.argument(optional = true) int dataI } @Kroll.method - public int finish(BufferProxy dataOut, @Kroll.argument(optional = true) int dataOutLength) { + public int finish(BufferProxy dataOut, @Kroll.argument(optional = true) int dataOutLength) + { try { // Get our cipher. CryptOptions o = prepareCryptOptions(null, 0, dataOut, dataOutLength); @@ -294,7 +315,8 @@ public int finish(BufferProxy dataOut, @Kroll.argument(optional = true) int data } @Kroll.method - public int reset(@Kroll.argument(optional = true) BufferProxy initializationBuffer) { + public int reset(@Kroll.argument(optional = true) BufferProxy initializationBuffer) + { if (initializationBuffer != null) { setProperty("initializationVector", initializationBuffer); } @@ -304,7 +326,8 @@ public int reset(@Kroll.argument(optional = true) BufferProxy initializationBuff } @Kroll.method(name = "release") - public int _release() { + public int _release() + { _encryptCipher = null; _decryptCipher = null; return CryptoModule.STATUS_SUCCESS; diff --git a/android/src/ti/crypto/utility/Hex.java b/android/src/ti/crypto/utility/Hex.java index 5bf6b75..9490caf 100644 --- a/android/src/ti/crypto/utility/Hex.java +++ b/android/src/ti/crypto/utility/Hex.java @@ -6,12 +6,14 @@ package ti.crypto.utility; -public class Hex { +public class Hex +{ /** * Prevent instantiation. */ - private Hex() { + private Hex() + { } /** @@ -21,7 +23,8 @@ private Hex() { * A hex string to convert. * @return The byte array. */ - public static byte[] convertFromHex(String s) { + public static byte[] convertFromHex(String s) + { // Source: http://stackoverflow.com/questions/140131/convert-a-string-representation-of-a-hex-dump-to-a-byte-array-using-java int len = s.length(); byte[] data = new byte[len / 2]; @@ -38,7 +41,8 @@ public static byte[] convertFromHex(String s) { * A byte array to convert. * @return The hex string. */ - public static String convertToHex(byte[] data) { + public static String convertToHex(byte[] data) + { StringBuffer result = new StringBuffer(); for (int i = 0; i < data.length; i++) { result.append(Integer.toHexString(data[i])); From d6b60ee1899d2ac66c6c798649f03f1d51828610 Mon Sep 17 00:00:00 2001 From: hansemannn Date: Wed, 15 Aug 2018 11:47:50 +0200 Subject: [PATCH 4/5] chore: build with 7.2.0.GA --- ios/Classes/TiCryptoModuleAssets.m | 11 ++++++++++- ios/metadata.json | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 ios/metadata.json diff --git a/ios/Classes/TiCryptoModuleAssets.m b/ios/Classes/TiCryptoModuleAssets.m index a406050..5302a8b 100644 --- a/ios/Classes/TiCryptoModuleAssets.m +++ b/ios/Classes/TiCryptoModuleAssets.m @@ -3,12 +3,21 @@ */ #import "TiCryptoModuleAssets.h" -extern NSData *dataWithHexString(NSString *hexString); +extern NSData* filterDataInRange(NSData* thedata, NSRange range); @implementation TiCryptoModuleAssets - (NSData *)moduleAsset { + + + return nil; +} + +- (NSData *)resolveModuleAsset:(NSString *)path +{ + + return nil; } diff --git a/ios/metadata.json b/ios/metadata.json new file mode 100644 index 0000000..43a62e5 --- /dev/null +++ b/ios/metadata.json @@ -0,0 +1 @@ +{"exports":[]} \ No newline at end of file From a53965ac8546b323d3c4cdc989c0900e5fd33369 Mon Sep 17 00:00:00 2001 From: hansemannn Date: Wed, 15 Aug 2018 12:18:03 +0200 Subject: [PATCH 5/5] chore: use latest 7.4.0 to make Jenkins happy --- ios/titanium.xcconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ios/titanium.xcconfig b/ios/titanium.xcconfig index af446d0..99c5215 100644 --- a/ios/titanium.xcconfig +++ b/ios/titanium.xcconfig @@ -4,8 +4,7 @@ // OF YOUR TITANIUM SDK YOU'RE BUILDING FOR // // -TITANIUM_SDK_VERSION = 7.2.0.GA - +TITANIUM_SDK_VERSION = 7.4.0.v20180814132725 // // THESE SHOULD BE OK GENERALLY AS-IS