diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29..0000000 diff --git a/BlueCryptor.podspec b/BlueCryptor.podspec index 672a062..970966e 100644 --- a/BlueCryptor.podspec +++ b/BlueCryptor.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "BlueCryptor" -s.version = "2.0.1" +s.version = "2.0.3" s.summary = "Swift cross-platform crypto library using CommonCrypto/libcrypto via Package Manager." s.homepage = "https://github.com/Kitura/BlueCryptor" s.license = { :type => "Apache License, Version 2.0" } diff --git a/Cryptor-iOS/Cryptor-iOS.h b/Cryptor-iOS/Cryptor-iOS.h deleted file mode 100644 index 325e1fe..0000000 --- a/Cryptor-iOS/Cryptor-iOS.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// Cryptor-iOS.h -// Cryptor-iOS -// -// Created by Bill Abt on 5/7/17. -// -// - -#import - -//! Project version number for Cryptor-iOS. -FOUNDATION_EXPORT double Cryptor_iOSVersionNumber; - -//! Project version string for Cryptor-iOS. -FOUNDATION_EXPORT const unsigned char Cryptor_iOSVersionString[]; - -// In this header, you should import all the public headers of your framework using statements like #import - - diff --git a/Cryptor-iOS/Info.plist b/Cryptor-iOS/Info.plist deleted file mode 100644 index fbe1e6b..0000000 --- a/Cryptor-iOS/Info.plist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleVersion - $(CURRENT_PROJECT_VERSION) - NSPrincipalClass - - - diff --git a/Cryptor.xcodeproj/project.pbxproj b/Cryptor.xcodeproj/project.pbxproj deleted file mode 100644 index 41dc682..0000000 --- a/Cryptor.xcodeproj/project.pbxproj +++ /dev/null @@ -1,747 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 8C7111EE2195B09A003CF4B3 /* SSLPointerTricks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C7111ED2195B09A003CF4B3 /* SSLPointerTricks.swift */; }; - 8C7111EF2195B09A003CF4B3 /* SSLPointerTricks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C7111ED2195B09A003CF4B3 /* SSLPointerTricks.swift */; }; - 8C9590301CC80A2300A2C2B4 /* libCryptor.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = "_____Product_Cryptor" /* libCryptor.dylib */; }; - 8C97EE131EBF75DD000E795B /* Cryptor-iOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C97EE111EBF75DD000E795B /* Cryptor-iOS.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 8C97EE181EBF76F0000E795B /* Crypto.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Crypto.swift /* Crypto.swift */; }; - 8C97EE191EBF76F0000E795B /* Cryptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Cryptor.swift /* Cryptor.swift */; }; - 8C97EE1A1EBF76F0000E795B /* Digest.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Digest.swift /* Digest.swift */; }; - 8C97EE1B1EBF76F0000E795B /* HMAC.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/HMAC.swift /* HMAC.swift */; }; - 8C97EE1C1EBF76F0000E795B /* KeyDerivation.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/KeyDerivation.swift /* KeyDerivation.swift */; }; - 8C97EE1D1EBF76F0000E795B /* Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Random.swift /* Random.swift */; }; - 8C97EE1E1EBF76F0000E795B /* Status.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Status.swift /* Status.swift */; }; - 8C97EE1F1EBF76F0000E795B /* StreamCryptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/StreamCryptor.swift /* StreamCryptor.swift */; }; - 8C97EE201EBF76F0000E795B /* Updatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Updateable.swift /* Updatable.swift */; }; - 8C97EE211EBF76F0000E795B /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Utilities.swift /* Utilities.swift */; }; - 8CF04E2A1D4FCECC00C27814 /* CryptorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C9590241CC807D400A2C2B4 /* CryptorTests.swift */; }; - __src_cc_ref_Sources/Crypto.swift /* Crypto.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Crypto.swift /* Crypto.swift */; }; - __src_cc_ref_Sources/Cryptor.swift /* Cryptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Cryptor.swift /* Cryptor.swift */; }; - __src_cc_ref_Sources/Digest.swift /* Digest.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Digest.swift /* Digest.swift */; }; - __src_cc_ref_Sources/HMAC.swift /* HMAC.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/HMAC.swift /* HMAC.swift */; }; - __src_cc_ref_Sources/KeyDerivation.swift /* KeyDerivation.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/KeyDerivation.swift /* KeyDerivation.swift */; }; - __src_cc_ref_Sources/Random.swift /* Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Random.swift /* Random.swift */; }; - __src_cc_ref_Sources/Status.swift /* Status.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Status.swift /* Status.swift */; }; - __src_cc_ref_Sources/StreamCryptor.swift /* StreamCryptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/StreamCryptor.swift /* StreamCryptor.swift */; }; - __src_cc_ref_Sources/Updateable.swift /* Updatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Updateable.swift /* Updatable.swift */; }; - __src_cc_ref_Sources/Utilities.swift /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Utilities.swift /* Utilities.swift */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - 8C9590311CC80A2300A2C2B4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = __RootObject_ /* Project object */; - proxyType = 1; - remoteGlobalIDString = "______Target_Cryptor"; - remoteInfo = Cryptor; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXFileReference section */ - 8C7111ED2195B09A003CF4B3 /* SSLPointerTricks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SSLPointerTricks.swift; path = Sources/Cryptor/SSLPointerTricks.swift; sourceTree = ""; }; - 8C9590241CC807D400A2C2B4 /* CryptorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CryptorTests.swift; path = Tests/CryptorTests/CryptorTests.swift; sourceTree = ""; }; - 8C95902B1CC80A2300A2C2B4 /* CryptorTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CryptorTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 8C97EE0F1EBF75DD000E795B /* Cryptor.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Cryptor.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 8C97EE111EBF75DD000E795B /* Cryptor-iOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Cryptor-iOS.h"; sourceTree = ""; }; - 8C97EE121EBF75DD000E795B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 8C9B7E631FEC01D90038D9C6 /* BlueCryptor.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = BlueCryptor.podspec; sourceTree = ""; }; - 8C9C42F01CD7881000045CFB /* LinuxMain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LinuxMain.swift; path = Tests/LinuxMain.swift; sourceTree = ""; }; - 8CD16C6C1CC81DE5007296B5 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; - 8CD16C6D1CC81DE5007296B5 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; - __PBXFileRef_Package.swift /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; - __PBXFileRef_Sources/Crypto.swift /* Crypto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Crypto.swift; path = Sources/Cryptor/Crypto.swift; sourceTree = ""; }; - __PBXFileRef_Sources/Cryptor.swift /* Cryptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Cryptor.swift; path = Sources/Cryptor/Cryptor.swift; sourceTree = ""; }; - __PBXFileRef_Sources/Digest.swift /* Digest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Digest.swift; path = Sources/Cryptor/Digest.swift; sourceTree = ""; }; - __PBXFileRef_Sources/HMAC.swift /* HMAC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = HMAC.swift; path = Sources/Cryptor/HMAC.swift; sourceTree = ""; }; - __PBXFileRef_Sources/KeyDerivation.swift /* KeyDerivation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = KeyDerivation.swift; path = Sources/Cryptor/KeyDerivation.swift; sourceTree = ""; }; - __PBXFileRef_Sources/Random.swift /* Random.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Random.swift; path = Sources/Cryptor/Random.swift; sourceTree = ""; }; - __PBXFileRef_Sources/Status.swift /* Status.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Status.swift; path = Sources/Cryptor/Status.swift; sourceTree = ""; }; - __PBXFileRef_Sources/StreamCryptor.swift /* StreamCryptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = StreamCryptor.swift; path = Sources/Cryptor/StreamCryptor.swift; sourceTree = ""; }; - __PBXFileRef_Sources/Updateable.swift /* Updatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Updatable.swift; path = Sources/Cryptor/Updatable.swift; sourceTree = ""; }; - __PBXFileRef_Sources/Utilities.swift /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Utilities.swift; path = Sources/Cryptor/Utilities.swift; sourceTree = ""; }; - "_____Product_Cryptor" /* libCryptor.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; path = libCryptor.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 8C9590281CC80A2300A2C2B4 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 8C9590301CC80A2300A2C2B4 /* libCryptor.dylib in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 8C97EE0B1EBF75DD000E795B /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - "___LinkPhase_Cryptor" /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 0; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 8C9590261CC807EA00A2C2B4 /* Tests */ = { - isa = PBXGroup; - children = ( - 8C9C42F11CD7904000045CFB /* CryptorTests */, - 8C9C42F01CD7881000045CFB /* LinuxMain.swift */, - ); - name = Tests; - sourceTree = ""; - }; - 8C97EE101EBF75DD000E795B /* Cryptor-iOS */ = { - isa = PBXGroup; - children = ( - 8C97EE111EBF75DD000E795B /* Cryptor-iOS.h */, - 8C97EE121EBF75DD000E795B /* Info.plist */, - ); - path = "Cryptor-iOS"; - sourceTree = ""; - }; - 8C9C42F11CD7904000045CFB /* CryptorTests */ = { - isa = PBXGroup; - children = ( - 8C9590241CC807D400A2C2B4 /* CryptorTests.swift */, - ); - name = CryptorTests; - sourceTree = ""; - }; - Dependencies_ /* Dependencies */ = { - isa = PBXGroup; - children = ( - ); - name = Dependencies; - sourceTree = ""; - }; - "___RootGroup_" = { - isa = PBXGroup; - children = ( - 8C9B7E631FEC01D90038D9C6 /* BlueCryptor.podspec */, - 8CD16C6C1CC81DE5007296B5 /* LICENSE */, - __PBXFileRef_Package.swift /* Package.swift */, - 8CD16C6D1CC81DE5007296B5 /* README.md */, - "_____Sources_" /* Sources */, - 8C9590261CC807EA00A2C2B4 /* Tests */, - Dependencies_ /* Dependencies */, - 8C97EE101EBF75DD000E795B /* Cryptor-iOS */, - "____Products_" /* Products */, - ); - sourceTree = ""; - }; - "____Products_" /* Products */ = { - isa = PBXGroup; - children = ( - "_____Product_Cryptor" /* libCryptor.dylib */, - 8C95902B1CC80A2300A2C2B4 /* CryptorTests.xctest */, - 8C97EE0F1EBF75DD000E795B /* Cryptor.framework */, - ); - name = Products; - sourceTree = ""; - }; - "_____Sources_" /* Sources */ = { - isa = PBXGroup; - children = ( - __PBXFileRef_Sources/Crypto.swift /* Crypto.swift */, - __PBXFileRef_Sources/Cryptor.swift /* Cryptor.swift */, - __PBXFileRef_Sources/Digest.swift /* Digest.swift */, - __PBXFileRef_Sources/HMAC.swift /* HMAC.swift */, - __PBXFileRef_Sources/KeyDerivation.swift /* KeyDerivation.swift */, - __PBXFileRef_Sources/Random.swift /* Random.swift */, - 8C7111ED2195B09A003CF4B3 /* SSLPointerTricks.swift */, - __PBXFileRef_Sources/Status.swift /* Status.swift */, - __PBXFileRef_Sources/StreamCryptor.swift /* StreamCryptor.swift */, - __PBXFileRef_Sources/Updateable.swift /* Updatable.swift */, - __PBXFileRef_Sources/Utilities.swift /* Utilities.swift */, - ); - name = Sources; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXHeadersBuildPhase section */ - 8C97EE0C1EBF75DD000E795B /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 8C97EE131EBF75DD000E795B /* Cryptor-iOS.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXHeadersBuildPhase section */ - -/* Begin PBXNativeTarget section */ - 8C95902A1CC80A2300A2C2B4 /* CryptorTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 8C9590331CC80A2300A2C2B4 /* Build configuration list for PBXNativeTarget "CryptorTests" */; - buildPhases = ( - 8C9590271CC80A2300A2C2B4 /* Sources */, - 8C9590281CC80A2300A2C2B4 /* Frameworks */, - 8C9590291CC80A2300A2C2B4 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 8C9590321CC80A2300A2C2B4 /* PBXTargetDependency */, - ); - name = CryptorTests; - productName = CryptorTests; - productReference = 8C95902B1CC80A2300A2C2B4 /* CryptorTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; - 8C97EE0E1EBF75DD000E795B /* Cryptor-iOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = 8C97EE161EBF75DD000E795B /* Build configuration list for PBXNativeTarget "Cryptor-iOS" */; - buildPhases = ( - 8C97EE171EBF76BC000E795B /* ShellScript */, - 8C97EE0A1EBF75DD000E795B /* Sources */, - 8C97EE0B1EBF75DD000E795B /* Frameworks */, - 8C97EE0C1EBF75DD000E795B /* Headers */, - 8C97EE0D1EBF75DD000E795B /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "Cryptor-iOS"; - productName = "Cryptor-iOS"; - productReference = 8C97EE0F1EBF75DD000E795B /* Cryptor.framework */; - productType = "com.apple.product-type.framework"; - }; - "______Target_Cryptor" /* Cryptor */ = { - isa = PBXNativeTarget; - buildConfigurationList = "_______Confs_Cryptor" /* Build configuration list for PBXNativeTarget "Cryptor" */; - buildPhases = ( - 8C95901E1CC7D85000A2C2B4 /* ShellScript */, - CompilePhase_Cryptor /* Sources */, - "___LinkPhase_Cryptor" /* Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = Cryptor; - productName = Cryptor; - productReference = "_____Product_Cryptor" /* libCryptor.dylib */; - productType = "com.apple.product-type.library.dynamic"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - __RootObject_ /* Project object */ = { - isa = PBXProject; - attributes = { - LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 1020; - TargetAttributes = { - 8C95902A1CC80A2300A2C2B4 = { - CreatedOnToolsVersion = 7.3; - LastSwiftMigration = 1000; - }; - 8C97EE0E1EBF75DD000E795B = { - CreatedOnToolsVersion = 8.3.2; - LastSwiftMigration = 1000; - ProvisioningStyle = Automatic; - }; - "______Target_Cryptor" = { - LastSwiftMigration = 1000; - }; - }; - }; - buildConfigurationList = "___RootConfs_" /* Build configuration list for PBXProject "Cryptor" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = en; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = "___RootGroup_"; - productRefGroup = "____Products_" /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - "______Target_Cryptor" /* Cryptor */, - 8C95902A1CC80A2300A2C2B4 /* CryptorTests */, - 8C97EE0E1EBF75DD000E795B /* Cryptor-iOS */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 8C9590291CC80A2300A2C2B4 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 8C97EE0D1EBF75DD000E795B /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXShellScriptBuildPhase section */ - 8C95901E1CC7D85000A2C2B4 /* ShellScript */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "#!/bin/bash\nCC_PATH=\"$SRCROOT/CommonCrypto\"\necho \"$CC_PATH\"\n\nCCMODMAP=$SDKROOT/usr/include/CommonCrypto/module.modulemap\nif [ -e \"$CCMODMAP\" ] ; then\nif [ -e \"$CC_PATH\" ] ; then\nrm -rf \"$CC_PATH\"\nfi\necho \"Modulemap already exists. Skipping generation...\"\nexit 0\nfi\n\nHEADER_FILE1=$SDKROOT/usr/include/CommonCrypto/CommonCrypto.h\nif [ ! -e $HEADER_FILE1 ] ; then\necho \"ERROR: The CommonCrypto.h header file could not be found.\"\nexit 1\nfi\n\nHEADER_FILE2=$SDKROOT/usr/include/CommonCrypto/CommonRandom.h\nif [ ! -e $HEADER_FILE2 ] ; then\necho \"ERROR: The CommonRandom.h header file could not be found.\"\nexit 1\nfi\n\nif [ -e \"$CC_PATH\" ] ; then\necho \"$CC_PATH exists...\"\nelse\nmkdir -p \"$CC_PATH\"\nfi\n\n# Write the module.map file\ncat <<_EOF_ > \"$CC_PATH/module.map\"\nmodule CommonCrypto [system] {\nheader \"$HEADER_FILE1\"\nheader \"$HEADER_FILE2\"\nexport *\n}\n\nmodule OpenSSL [system] {\nheader \"/usr/local/opt/openssl/include/openssl/conf.h\"\nheader \"/usr/local/opt/openssl/include/openssl/evp.h\"\nheader \"/usr/local/opt/openssl/include/openssl/err.h\"\nheader \"/usr/local/opt/openssl/include/openssl/bio.h\"\nheader \"/usr/local/opt/openssl/include/openssl/ssl.h\"\nheader \"/usr/local/opt/openssl/include/openssl/md4.h\"\nheader \"/usr/local/opt/openssl/include/openssl/md5.h\"\nheader \"/usr/local/opt/openssl/include/openssl/sha.h\"\nheader \"/usr/local/opt/openssl/include/openssl/hmac.h\"\nheader \"/usr/local/opt/openssl/include/openssl/rand.h\"\nlink \"ssl\"\nlink \"crypto\"\n}\n_EOF_\necho \"Created CommonCrypto Module Map. CommonCrypto Framework now available.\"\n"; - }; - 8C97EE171EBF76BC000E795B /* ShellScript */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "#!/bin/bash\nCC_PATH=\"$SRCROOT/CommonCrypto\"\necho \"$CC_PATH\"\n\nCCMODMAP=$SDKROOT/usr/include/CommonCrypto/module.modulemap\nif [ -e \"$CCMODMAP\" ] ; then\nif [ -e \"$CC_PATH\" ] ; then\nrm -rf \"$CC_PATH\"\nfi\necho \"Modulemap already exists. Skipping generation...\"\nexit 0\nfi\n\nHEADER_FILE1=$SDKROOT/usr/include/CommonCrypto/CommonCrypto.h\nif [ ! -e $HEADER_FILE1 ] ; then\necho \"ERROR: The CommonCrypto.h header file could not be found.\"\nexit 1\nfi\n\nHEADER_FILE2=$SDKROOT/usr/include/CommonCrypto/CommonRandom.h\nif [ ! -e $HEADER_FILE2 ] ; then\necho \"ERROR: The CommonRandom.h header file could not be found.\"\nexit 1\nfi\n\nif [ -e \"$CC_PATH\" ] ; then\necho \"$CC_PATH exists...\"\nelse\nmkdir -p \"$CC_PATH\"\nfi\n\n# Write the module.map file\ncat <<_EOF_ > \"$CC_PATH/module.map\"\nmodule CommonCrypto [system] {\nheader \"$HEADER_FILE1\"\nheader \"$HEADER_FILE2\"\nexport *\n}\n\nmodule OpenSSL [system] {\nheader \"/usr/local/opt/openssl/include/openssl/conf.h\"\nheader \"/usr/local/opt/openssl/include/openssl/evp.h\"\nheader \"/usr/local/opt/openssl/include/openssl/err.h\"\nheader \"/usr/local/opt/openssl/include/openssl/bio.h\"\nheader \"/usr/local/opt/openssl/include/openssl/ssl.h\"\nheader \"/usr/local/opt/openssl/include/openssl/md4.h\"\nheader \"/usr/local/opt/openssl/include/openssl/md5.h\"\nheader \"/usr/local/opt/openssl/include/openssl/sha.h\"\nheader \"/usr/local/opt/openssl/include/openssl/hmac.h\"\nheader \"/usr/local/opt/openssl/include/openssl/rand.h\"\nlink \"ssl\"\nlink \"crypto\"\n}\n_EOF_\necho \"Created CommonCrypto Module Map. CommonCrypto Framework now available.\"\n"; - }; -/* End PBXShellScriptBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 8C9590271CC80A2300A2C2B4 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 8CF04E2A1D4FCECC00C27814 /* CryptorTests.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 8C97EE0A1EBF75DD000E795B /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 8C97EE181EBF76F0000E795B /* Crypto.swift in Sources */, - 8C97EE191EBF76F0000E795B /* Cryptor.swift in Sources */, - 8C7111EF2195B09A003CF4B3 /* SSLPointerTricks.swift in Sources */, - 8C97EE1A1EBF76F0000E795B /* Digest.swift in Sources */, - 8C97EE1B1EBF76F0000E795B /* HMAC.swift in Sources */, - 8C97EE1C1EBF76F0000E795B /* KeyDerivation.swift in Sources */, - 8C97EE1D1EBF76F0000E795B /* Random.swift in Sources */, - 8C97EE1E1EBF76F0000E795B /* Status.swift in Sources */, - 8C97EE1F1EBF76F0000E795B /* StreamCryptor.swift in Sources */, - 8C97EE201EBF76F0000E795B /* Updatable.swift in Sources */, - 8C97EE211EBF76F0000E795B /* Utilities.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - CompilePhase_Cryptor /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 0; - files = ( - __src_cc_ref_Sources/Crypto.swift /* Crypto.swift in Sources */, - __src_cc_ref_Sources/Cryptor.swift /* Cryptor.swift in Sources */, - 8C7111EE2195B09A003CF4B3 /* SSLPointerTricks.swift in Sources */, - __src_cc_ref_Sources/Digest.swift /* Digest.swift in Sources */, - __src_cc_ref_Sources/HMAC.swift /* HMAC.swift in Sources */, - __src_cc_ref_Sources/KeyDerivation.swift /* KeyDerivation.swift in Sources */, - __src_cc_ref_Sources/Random.swift /* Random.swift in Sources */, - __src_cc_ref_Sources/Status.swift /* Status.swift in Sources */, - __src_cc_ref_Sources/StreamCryptor.swift /* StreamCryptor.swift in Sources */, - __src_cc_ref_Sources/Updateable.swift /* Updatable.swift in Sources */, - __src_cc_ref_Sources/Utilities.swift /* Utilities.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - 8C9590321CC80A2300A2C2B4 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = "______Target_Cryptor" /* Cryptor */; - targetProxy = 8C9590311CC80A2300A2C2B4 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin XCBuildConfiguration section */ - 8C9590341CC80A2300A2C2B4 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "-"; - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = /usr/local/opt/openssl/include; - INFOPLIST_FILE = Tests/CryptorTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - LIBRARY_SEARCH_PATHS = /usr/local/opt/openssl/lib; - MACOSX_DEPLOYMENT_TARGET = 10.11; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - OTHER_CFLAGS = "-I/usr/local/opt/openssl/include"; - PRODUCT_BUNDLE_IDENTIFIER = com.ibm.oss.CryptorTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; - USER_HEADER_SEARCH_PATHS = /usr/local/opt/openssl/include; - }; - name = Debug; - }; - 8C9590351CC80A2300A2C2B4 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "-"; - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = /usr/local/opt/openssl/include; - INFOPLIST_FILE = Tests/CryptorTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - LIBRARY_SEARCH_PATHS = /usr/local/opt/openssl/lib; - MACOSX_DEPLOYMENT_TARGET = 10.11; - MTL_ENABLE_DEBUG_INFO = NO; - OTHER_CFLAGS = "-I/usr/local/opt/openssl/include"; - PRODUCT_BUNDLE_IDENTIFIER = com.ibm.oss.CryptorTests; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 5.0; - USER_HEADER_SEARCH_PATHS = /usr/local/opt/openssl/include; - }; - name = Release; - }; - 8C97EE141EBF75DD000E795B /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CODE_SIGN_IDENTITY = ""; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = dwarf; - DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - INFOPLIST_FILE = "Cryptor-iOS/Info.plist"; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MTL_ENABLE_DEBUG_INFO = YES; - PRODUCT_BUNDLE_IDENTIFIER = com.ibm.oss.Cryptor; - PRODUCT_NAME = Cryptor; - SDKROOT = iphoneos; - SKIP_INSTALL = YES; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_INCLUDE_PATHS = "\"$SRCROOT/CommonCrypto\""; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Debug; - }; - 8C97EE151EBF75DD000E795B /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CODE_SIGN_IDENTITY = ""; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_NS_ASSERTIONS = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - INFOPLIST_FILE = "Cryptor-iOS/Info.plist"; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MTL_ENABLE_DEBUG_INFO = NO; - PRODUCT_BUNDLE_IDENTIFIER = com.ibm.oss.Cryptor; - PRODUCT_NAME = Cryptor; - SDKROOT = iphoneos; - SKIP_INSTALL = YES; - SWIFT_INCLUDE_PATHS = "\"$SRCROOT/CommonCrypto\""; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - VALIDATE_PRODUCT = YES; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Release; - }; - _ReleaseConf_Cryptor /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ENABLE_OBJC_WEAK = YES; - COMBINE_HIDPI_IMAGES = YES; - DYLIB_INSTALL_NAME_BASE = "$(CONFIGURATION_BUILD_DIR)"; - ENABLE_TESTABILITY = YES; - FRAMEWORK_SEARCH_PATHS = /usr/local/opt/openssl/include; - HEADER_SEARCH_PATHS = /usr/local/opt/openssl/include; - LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx"; - LIBRARY_SEARCH_PATHS = /usr/local/opt/openssl/lib; - MACOSX_DEPLOYMENT_TARGET = 10.10; - OTHER_CFLAGS = "-I/usr/local/opt/openssl/include"; - OTHER_LDFLAGS = ""; - OTHER_SWIFT_FLAGS = "-DXcode"; - PRODUCT_MODULE_NAME = Cryptor; - PRODUCT_NAME = "lib$(TARGET_NAME)"; - SWIFT_INCLUDE_PATHS = "\"$SRCROOT/CommonCrypto\""; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 5.0; - USER_HEADER_SEARCH_PATHS = /usr/local/opt/openssl/include; - }; - name = Release; - }; - "___DebugConf_Cryptor" /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ENABLE_OBJC_WEAK = YES; - COMBINE_HIDPI_IMAGES = YES; - DYLIB_INSTALL_NAME_BASE = "$(CONFIGURATION_BUILD_DIR)"; - ENABLE_TESTABILITY = YES; - FRAMEWORK_SEARCH_PATHS = /usr/local/opt/openssl/include; - HEADER_SEARCH_PATHS = /usr/local/opt/openssl/include; - LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx"; - LIBRARY_SEARCH_PATHS = /usr/local/opt/openssl/lib; - MACOSX_DEPLOYMENT_TARGET = 10.10; - OTHER_CFLAGS = "-I/usr/local/opt/openssl/include"; - OTHER_LDFLAGS = ""; - OTHER_SWIFT_FLAGS = "-DXcode"; - PRODUCT_MODULE_NAME = Cryptor; - PRODUCT_NAME = "lib$(TARGET_NAME)"; - SWIFT_INCLUDE_PATHS = "\"$SRCROOT/CommonCrypto\""; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 5.0; - USER_HEADER_SEARCH_PATHS = /usr/local/opt/openssl/include; - }; - name = Debug; - }; - "_____Release_" /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - SWIFT_VERSION = 3.0; - }; - name = Release; - }; - "_______Debug_" /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - ONLY_ACTIVE_ARCH = YES; - SWIFT_VERSION = 3.0; - }; - name = Debug; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 8C9590331CC80A2300A2C2B4 /* Build configuration list for PBXNativeTarget "CryptorTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 8C9590341CC80A2300A2C2B4 /* Debug */, - 8C9590351CC80A2300A2C2B4 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Debug; - }; - 8C97EE161EBF75DD000E795B /* Build configuration list for PBXNativeTarget "Cryptor-iOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 8C97EE141EBF75DD000E795B /* Debug */, - 8C97EE151EBF75DD000E795B /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Debug; - }; - "___RootConfs_" /* Build configuration list for PBXProject "Cryptor" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - "_______Debug_" /* Debug */, - "_____Release_" /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Debug; - }; - "_______Confs_Cryptor" /* Build configuration list for PBXNativeTarget "Cryptor" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - "___DebugConf_Cryptor" /* Debug */, - _ReleaseConf_Cryptor /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Debug; - }; -/* End XCConfigurationList section */ - }; - rootObject = __RootObject_ /* Project object */; -} diff --git a/Cryptor.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Cryptor.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 919434a..0000000 --- a/Cryptor.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/Cryptor.xcodeproj/xcshareddata/xcschemes/Cryptor-iOS.xcscheme b/Cryptor.xcodeproj/xcshareddata/xcschemes/Cryptor-iOS.xcscheme deleted file mode 100644 index f6a307d..0000000 --- a/Cryptor.xcodeproj/xcshareddata/xcschemes/Cryptor-iOS.xcscheme +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Cryptor.xcodeproj/xcshareddata/xcschemes/Cryptor.xcscheme b/Cryptor.xcodeproj/xcshareddata/xcschemes/Cryptor.xcscheme deleted file mode 100644 index cf915bf..0000000 --- a/Cryptor.xcodeproj/xcshareddata/xcschemes/Cryptor.xcscheme +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Cryptor.xcodeproj/xcshareddata/xcschemes/CryptorTests.xcscheme b/Cryptor.xcodeproj/xcshareddata/xcschemes/CryptorTests.xcscheme deleted file mode 100644 index 02c6ba3..0000000 --- a/Cryptor.xcodeproj/xcshareddata/xcschemes/CryptorTests.xcscheme +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/Cryptor.xcodeproj/xcshareddata/xcschemes/xcschememanagement.plist b/Cryptor.xcodeproj/xcshareddata/xcschemes/xcschememanagement.plist deleted file mode 100644 index 864b769..0000000 --- a/Cryptor.xcodeproj/xcshareddata/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,12 +0,0 @@ - - - - SchemeUserState - - Cryptor.xcscheme - - - SuppressBuildableAutocreation - - - diff --git a/Package.swift b/Package.swift index 80332d7..c17e3f6 100644 --- a/Package.swift +++ b/Package.swift @@ -32,20 +32,26 @@ var targetDependencies: [Target.Dependency] = [] let package = Package( name: "Cryptor", + platforms: [ + .macOS(.v10_11), + .iOS(.v10), + .tvOS(.v10), + .watchOS(.v2), + ], products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( name: "Cryptor", targets: ["Cryptor"]), - ], + ], dependencies: dependencies, targets: [ .target( name: "Cryptor", - dependencies: targetDependencies, - exclude: ["Info.plist"]), + dependencies: targetDependencies), .testTarget( name: "CryptorTests", dependencies: ["Cryptor"]), - ] + ], + swiftLanguageVersions: [.v5] ) diff --git a/Sources/Cryptor/Crypto.swift b/Sources/Cryptor/Crypto.swift index f41e453..f868e5d 100755 --- a/Sources/Cryptor/Crypto.swift +++ b/Sources/Cryptor/Crypto.swift @@ -87,21 +87,12 @@ extension Data: CryptoDigest { // This force unwrap may look scary but for CommonCrypto this cannot fail. // The API allows for optionals to support the OpenSSL implementation which can. - #if swift(>=5.0) - return self.withUnsafeBytes() { - - let result = (Digest(using: algorithm).update(from: $0.baseAddress!, byteCount: self.count)?.final())! - let data = type(of: self).init(bytes: result, count: result.count) - return data - } - #else - return self.withUnsafeBytes() { (buffer: UnsafePointer) -> Data in - - let result = (Digest(using: algorithm).update(from: buffer, byteCount: self.count)?.final())! - let data = type(of: self).init(bytes: result, count: result.count) - return data - } - #endif + return self.withUnsafeBytes() { + + let result = (Digest(using: algorithm).update(from: $0.baseAddress!, byteCount: self.count)?.final())! + let data = type(of: self).init(bytes: result, count: result.count) + return data + } } } diff --git a/Sources/Cryptor/Digest.swift b/Sources/Cryptor/Digest.swift index 5411256..7743ee4 100755 --- a/Sources/Cryptor/Digest.swift +++ b/Sources/Cryptor/Digest.swift @@ -17,11 +17,11 @@ import Foundation -#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) - import CommonCrypto -#elseif os(Linux) - import OpenSSL - typealias CC_LONG = size_t +#if os(Linux) + import OpenSSL + typealias CC_LONG = size_t +#else + import CommonCrypto #endif /// @@ -87,59 +87,59 @@ public class Digest: Updatable { switch algorithm { case .md2: - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + fatalError("MD2 digest not supported by OpenSSL") + #else engine = DigestEngineCC(initializer:CC_MD2_Init, updater:CC_MD2_Update, finalizer:CC_MD2_Final, length:CC_MD2_DIGEST_LENGTH) - #elseif os(Linux) - fatalError("MD2 digest not supported by OpenSSL") #endif case .md4: - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + engine = DigestEngineCC(initializer:MD4_Init, updater:MD4_Update, finalizer:MD4_Final, length:MD4_DIGEST_LENGTH) + #else engine = DigestEngineCC(initializer:CC_MD4_Init, updater:CC_MD4_Update, finalizer:CC_MD4_Final, length:CC_MD4_DIGEST_LENGTH) - #elseif os(Linux) - engine = DigestEngineCC(initializer:MD4_Init, updater:MD4_Update, finalizer:MD4_Final, length:MD4_DIGEST_LENGTH) #endif case .md5: - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + engine = DigestEngineCC(initializer:MD5_Init, updater:MD5_Update, finalizer:MD5_Final, length:MD5_DIGEST_LENGTH) + #else engine = DigestEngineCC(initializer:CC_MD5_Init, updater:CC_MD5_Update, finalizer:CC_MD5_Final, length:CC_MD5_DIGEST_LENGTH) - #elseif os(Linux) - engine = DigestEngineCC(initializer:MD5_Init, updater:MD5_Update, finalizer:MD5_Final, length:MD5_DIGEST_LENGTH) #endif case .sha1: - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) - engine = DigestEngineCC(initializer:CC_SHA1_Init, updater:CC_SHA1_Update, finalizer:CC_SHA1_Final, length:CC_SHA1_DIGEST_LENGTH) - #elseif os(Linux) - engine = DigestEngineCC(initializer:SHA1_Init, updater:SHA1_Update, finalizer:SHA1_Final, length:SHA_DIGEST_LENGTH) + #if os(Linux) + engine = DigestEngineCC(initializer:SHA1_Init, updater:SHA1_Update, finalizer:SHA1_Final, length:SHA_DIGEST_LENGTH) + #else + engine = DigestEngineCC(initializer:CC_SHA1_Init, updater:CC_SHA1_Update, finalizer:CC_SHA1_Final, length:CC_SHA1_DIGEST_LENGTH) #endif case .sha224: - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + engine = DigestEngineCC(initializer:SHA224_Init, updater:SHA224_Update, finalizer:SHA224_Final, length:SHA224_DIGEST_LENGTH) + #else engine = DigestEngineCC(initializer:CC_SHA224_Init, updater:CC_SHA224_Update, finalizer:CC_SHA224_Final, length:CC_SHA224_DIGEST_LENGTH) - #elseif os(Linux) - engine = DigestEngineCC(initializer:SHA224_Init, updater:SHA224_Update, finalizer:SHA224_Final, length:SHA224_DIGEST_LENGTH) #endif case .sha256: - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + engine = DigestEngineCC(initializer: SHA256_Init, updater:SHA256_Update, finalizer:SHA256_Final, length:SHA256_DIGEST_LENGTH) + #else engine = DigestEngineCC(initializer:CC_SHA256_Init, updater:CC_SHA256_Update, finalizer:CC_SHA256_Final, length:CC_SHA256_DIGEST_LENGTH) - #elseif os(Linux) - engine = DigestEngineCC(initializer: SHA256_Init, updater:SHA256_Update, finalizer:SHA256_Final, length:SHA256_DIGEST_LENGTH) #endif case .sha384: - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + engine = DigestEngineCC(initializer:SHA384_Init, updater:SHA384_Update, finalizer:SHA384_Final, length:SHA384_DIGEST_LENGTH) + #else engine = DigestEngineCC(initializer:CC_SHA384_Init, updater:CC_SHA384_Update, finalizer:CC_SHA384_Final, length:CC_SHA384_DIGEST_LENGTH) - #elseif os(Linux) - engine = DigestEngineCC(initializer:SHA384_Init, updater:SHA384_Update, finalizer:SHA384_Final, length:SHA384_DIGEST_LENGTH) #endif case .sha512: - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + engine = DigestEngineCC(initializer:SHA512_Init, updater:SHA512_Update, finalizer:SHA512_Final, length:SHA512_DIGEST_LENGTH) + #else engine = DigestEngineCC(initializer:CC_SHA512_Init, updater:CC_SHA512_Update, finalizer:CC_SHA512_Final, length:CC_SHA512_DIGEST_LENGTH) - #elseif os(Linux) - engine = DigestEngineCC(initializer:SHA512_Init, updater:SHA512_Update, finalizer:SHA512_Final, length:SHA512_DIGEST_LENGTH) #endif } } @@ -239,12 +239,7 @@ private class DigestEngineCC: DigestEngine { /// Cleanup /// deinit { - - #if swift(>=4.1) - context.deallocate() - #else - context.deallocate(capacity: 1) - #endif + context.deallocate() } /// diff --git a/Sources/Cryptor/HMAC.swift b/Sources/Cryptor/HMAC.swift index 086cd62..ee0187d 100755 --- a/Sources/Cryptor/HMAC.swift +++ b/Sources/Cryptor/HMAC.swift @@ -17,10 +17,10 @@ import Foundation -#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) +#if os(Linux) + import OpenSSL +#else import CommonCrypto -#elseif os(Linux) - import OpenSSL #endif /// @@ -51,7 +51,28 @@ public class HMAC: Updatable { /// Secure Hash Algorithm 2 512-bit case sha512 - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + + func nativeValue() -> OpaquePointer? { + + switch self { + + case .sha1: + return .init(EVP_sha1()) + case .md5: + return .init(EVP_md5()) + case .sha224: + return .init(EVP_sha224()) + case .sha256: + return .init(EVP_sha256()) + case .sha384: + return .init(EVP_sha384()) + case .sha512: + return .init(EVP_sha512()) + } + } + + #else static let fromNative: [CCHmacAlgorithm: Algorithm] = [ CCHmacAlgorithm(kCCHmacAlgSHA1): .sha1, @@ -86,27 +107,6 @@ public class HMAC: Updatable { } } - #elseif os(Linux) - - func nativeValue() -> OpaquePointer? { - - switch self { - - case .sha1: - return .init(EVP_sha1()) - case .md5: - return .init(EVP_md5()) - case .sha224: - return .init(EVP_sha224()) - case .sha256: - return .init(EVP_sha256()) - case .sha384: - return .init(EVP_sha384()) - case .sha512: - return .init(EVP_sha512()) - } - } - #endif /// @@ -114,7 +114,25 @@ public class HMAC: Updatable { /// public func digestLength() -> Int { - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + + switch self { + + case .sha1: + return Int(SHA_DIGEST_LENGTH) + case .md5: + return Int(MD5_DIGEST_LENGTH) + case .sha224: + return Int(SHA224_DIGEST_LENGTH) + case .sha256: + return Int(SHA256_DIGEST_LENGTH) + case .sha384: + return Int(SHA384_DIGEST_LENGTH) + case .sha512: + return Int(SHA512_DIGEST_LENGTH) + } + + #else switch self { @@ -132,38 +150,20 @@ public class HMAC: Updatable { return Int(CC_SHA512_DIGEST_LENGTH) } - #elseif os(Linux) - - switch self { - - case .sha1: - return Int(SHA_DIGEST_LENGTH) - case .md5: - return Int(MD5_DIGEST_LENGTH) - case .sha224: - return Int(SHA224_DIGEST_LENGTH) - case .sha256: - return Int(SHA256_DIGEST_LENGTH) - case .sha384: - return Int(SHA384_DIGEST_LENGTH) - case .sha512: - return Int(SHA512_DIGEST_LENGTH) - } - #endif } } /// Context - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) - + #if os(Linux) + + typealias Context = OpaquePointer? + + #else + typealias Context = UnsafeMutablePointer - #elseif os(Linux) - - typealias Context = OpaquePointer? - #endif /// Status of the calculation @@ -189,10 +189,10 @@ public class HMAC: Updatable { init(using algorithm: Algorithm, keyBuffer: UnsafeRawPointer, keyByteCount: Int) { self.algorithm = algorithm - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + HMAC_Init_wrapper(context, keyBuffer, Int32(keyByteCount), .make(optional: algorithm.nativeValue())) + #else CCHmacInit(context, algorithm.nativeValue(), keyBuffer, size_t(keyByteCount)) - #elseif os(Linux) - HMAC_Init_wrapper(context, keyBuffer, Int32(keyByteCount), .make(optional: algorithm.nativeValue())) #endif } @@ -203,31 +203,19 @@ public class HMAC: Updatable { /// - algorithm: Selects the algorithm /// - key: Specifies the key as Data /// - public init(using algorithm: Algorithm, key: Data) { - - self.algorithm = algorithm - #if swift(>=5.0) - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) - key.withUnsafeBytes() { - CCHmacInit(context, algorithm.nativeValue(), $0.baseAddress, size_t(key.count)) - } - #elseif os(Linux) - _ = key.withUnsafeBytes() { - HMAC_Init_wrapper(context, $0.baseAddress, Int32(key.count), .make(optional: algorithm.nativeValue())) - } - #endif - #else - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) - key.withUnsafeBytes() { (buffer: UnsafePointer) in - CCHmacInit(context, algorithm.nativeValue(), buffer, size_t(key.count)) - } - #elseif os(Linux) - _ = key.withUnsafeBytes() { (buffer: UnsafePointer) in - HMAC_Init_wrapper(context, buffer, Int32(key.count), .make(optional: algorithm.nativeValue())) - } - #endif - #endif - } + public init(using algorithm: Algorithm, key: Data) { + + self.algorithm = algorithm + #if os(Linux) + _ = key.withUnsafeBytes() { + HMAC_Init_wrapper(context, $0.baseAddress, Int32(key.count), .make(optional: algorithm.nativeValue())) + } + #else + key.withUnsafeBytes() { + CCHmacInit(context, algorithm.nativeValue(), $0.baseAddress, size_t(key.count)) + } + #endif + } /// /// Creates a new HMAC instance with the specified algorithm and key. @@ -239,10 +227,10 @@ public class HMAC: Updatable { public init(using algorithm: Algorithm, key: NSData) { self.algorithm = algorithm - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + HMAC_Init_wrapper(context, key.bytes, Int32(key.length), .make(optional: algorithm.nativeValue())) + #else CCHmacInit(context, algorithm.nativeValue(), key.bytes, size_t(key.length)) - #elseif os(Linux) - HMAC_Init_wrapper(context, key.bytes, Int32(key.length), .make(optional: algorithm.nativeValue())) #endif } @@ -256,10 +244,10 @@ public class HMAC: Updatable { public init(using algorithm: Algorithm, key: [UInt8]) { self.algorithm = algorithm - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + HMAC_Init_wrapper(context, key, Int32(key.count), .make(optional: algorithm.nativeValue())) + #else CCHmacInit(context, algorithm.nativeValue(), key, size_t(key.count)) - #elseif os(Linux) - HMAC_Init_wrapper(context, key, Int32(key.count), .make(optional: algorithm.nativeValue())) #endif } @@ -274,10 +262,10 @@ public class HMAC: Updatable { public init(using algorithm: Algorithm, key: String) { self.algorithm = algorithm - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + HMAC_Init_wrapper(context, key, Int32(key.utf8.count), .make(optional: algorithm.nativeValue())) + #else CCHmacInit(context, algorithm.nativeValue(), key, size_t(key.lengthOfBytes(using: String.Encoding.utf8))) - #elseif os(Linux) - HMAC_Init_wrapper(context, key, Int32(key.utf8.count), .make(optional: algorithm.nativeValue())) #endif } @@ -288,11 +276,7 @@ public class HMAC: Updatable { #if os(Linux) HMAC_CTX_free_wrapper(.make(optional: context)) #else - #if swift(>=4.1) - context.deallocate() - #else - context.deallocate(capacity: 1) - #endif + context.deallocate() #endif } @@ -307,10 +291,10 @@ public class HMAC: Updatable { /// public func update(from buffer: UnsafeRawPointer, byteCount: size_t) -> Self? { - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + HMAC_Update(context, buffer.assumingMemoryBound(to: UInt8.self), byteCount) + #else CCHmacUpdate(context, buffer, byteCount) - #elseif os(Linux) - HMAC_Update(context, buffer.assumingMemoryBound(to: UInt8.self), byteCount) #endif return self } @@ -323,11 +307,11 @@ public class HMAC: Updatable { public func final() -> [UInt8] { var hmac = Array(repeating: 0, count:algorithm.digestLength()) - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + var length: UInt32 = 0 + HMAC_Final(context, &hmac, &length) + #else CCHmacFinal(context, &hmac) - #elseif os(Linux) - var length: UInt32 = 0 - HMAC_Final(context, &hmac, &length) #endif return hmac } diff --git a/Sources/Cryptor/Info.plist b/Sources/Cryptor/Info.plist deleted file mode 100755 index d3de8ee..0000000 --- a/Sources/Cryptor/Info.plist +++ /dev/null @@ -1,26 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - $(CURRENT_PROJECT_VERSION) - NSPrincipalClass - - - diff --git a/Sources/Cryptor/KeyDerivation.swift b/Sources/Cryptor/KeyDerivation.swift index 7fa04d5..1eef65c 100755 --- a/Sources/Cryptor/KeyDerivation.swift +++ b/Sources/Cryptor/KeyDerivation.swift @@ -17,10 +17,10 @@ import Foundation -#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) +#if os(Linux) + import OpenSSL +#else import CommonCrypto -#elseif os(Linux) - import OpenSSL #endif /// @@ -46,8 +46,29 @@ public class PBKDF { /// Secure Hash Algorithm 2 512-bit case sha512 - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) - /// Return the OS native value + #if os(Linux) + + /// Return the OS native value + func nativeValue() -> OpaquePointer? { + + switch self { + + case .sha1: + return .init(EVP_sha1()) + case .sha224: + return .init(EVP_sha224()) + case .sha256: + return .init(EVP_sha256()) + case .sha384: + return .init(EVP_sha384()) + case .sha512: + return .init(EVP_sha512()) + } + } + + #else + + /// Return the OS native value func nativeValue() -> CCPseudoRandomAlgorithm { switch self { @@ -65,26 +86,6 @@ public class PBKDF { } } - #elseif os(Linux) - - /// Return the OS native value - func nativeValue() -> OpaquePointer? { - - switch self { - - case .sha1: - return .init(EVP_sha1()) - case .sha224: - return .init(EVP_sha224()) - case .sha256: - return .init(EVP_sha256()) - case .sha384: - return .init(EVP_sha384()) - case .sha512: - return .init(EVP_sha512()) - } - } - #endif } @@ -103,11 +104,11 @@ public class PBKDF { /// public class func calibrate(passwordLength: Int, saltLength: Int, algorithm: PseudoRandomAlgorithm, derivedKeyLength: Int, msec: UInt32) -> UInt { - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + // Value as per RFC 2898. + return UInt(1000 * UInt(msec)) + #else return UInt(CCCalibratePBKDF(CCPBKDFAlgorithm(kCCPBKDF2), passwordLength, saltLength, algorithm.nativeValue(), derivedKeyLength, msec)) - #elseif os(Linux) - // Value as per RFC 2898. - return UInt(1000 * UInt(msec)) #endif } @@ -127,19 +128,19 @@ public class PBKDF { public class func deriveKey(fromPassword password: String, salt: String, prf: PseudoRandomAlgorithm, rounds: uint, derivedKeyLength: UInt) throws -> [UInt8] { var derivedKey = Array(repeating: 0, count:Int(derivedKeyLength)) - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + let status = PKCS5_PBKDF2_HMAC(password, Int32(password.utf8.count), salt, Int32(salt.utf8.count), Int32(rounds), .make(optional: prf.nativeValue()), Int32(derivedKey.count), &derivedKey) + if status != 1 { + let error = ERR_get_error() + + throw CryptorError.fail(Int32(error), "ERROR: PKCS5_PBKDF2_HMAC failed, reason: \(errToString(ERR_error_string(error, nil)))") + } + #else let status: Int32 = CCKeyDerivationPBKDF(CCPBKDFAlgorithm(kCCPBKDF2), password, password.utf8.count, salt, salt.utf8.count, prf.nativeValue(), rounds, &derivedKey, derivedKey.count) if status != Int32(kCCSuccess) { throw CryptorError.fail(status, "ERROR: CCKeyDerivationPBDK failed with status \(status).") } - #elseif os(Linux) - let status = PKCS5_PBKDF2_HMAC(password, Int32(password.utf8.count), salt, Int32(salt.utf8.count), Int32(rounds), .make(optional: prf.nativeValue()), Int32(derivedKey.count), &derivedKey) - if status != 1 { - let error = ERR_get_error() - - throw CryptorError.fail(Int32(error), "ERROR: PKCS5_PBKDF2_HMAC failed, reason: \(errToString(ERR_error_string(error, nil)))") - } #endif return derivedKey } @@ -159,19 +160,19 @@ public class PBKDF { public class func deriveKey(fromPassword password: String, salt: [UInt8], prf: PseudoRandomAlgorithm, rounds: uint, derivedKeyLength: UInt) throws -> [UInt8] { var derivedKey = Array(repeating: 0, count:Int(derivedKeyLength)) - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + let status = PKCS5_PBKDF2_HMAC(password, Int32(password.utf8.count), salt, Int32(salt.count), Int32(rounds), .make(optional: prf.nativeValue()), Int32(derivedKey.count), &derivedKey) + if status != 1 { + let error = ERR_get_error() + + throw CryptorError.fail(Int32(error), "ERROR: PKCS5_PBKDF2_HMAC failed, reason: \(errToString(ERR_error_string(error, nil)))") + } + #else let status: Int32 = CCKeyDerivationPBKDF(CCPBKDFAlgorithm(kCCPBKDF2), password, password.utf8.count, salt, salt.count, prf.nativeValue(), rounds, &derivedKey, derivedKey.count) if status != Int32(kCCSuccess) { throw CryptorError.fail(status, "ERROR: CCKeyDerivationPBDK failed with status \(status).") } - #elseif os(Linux) - let status = PKCS5_PBKDF2_HMAC(password, Int32(password.utf8.count), salt, Int32(salt.count), Int32(rounds), .make(optional: prf.nativeValue()), Int32(derivedKey.count), &derivedKey) - if status != 1 { - let error = ERR_get_error() - - throw CryptorError.fail(Int32(error), "ERROR: PKCS5_PBKDF2_HMAC failed, reason: \(errToString(ERR_error_string(error, nil)))") - } #endif return derivedKey } @@ -193,19 +194,19 @@ public class PBKDF { /// public class func deriveKey(fromPassword password: UnsafePointer, passwordLen: Int, salt: UnsafePointer, saltLen: Int, prf: PseudoRandomAlgorithm, rounds: uint, derivedKey: UnsafeMutablePointer, derivedKeyLen: Int) throws { - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + let status = PKCS5_PBKDF2_HMAC(password, Int32(passwordLen), salt, Int32(saltLen), Int32(rounds), .make(optional: prf.nativeValue()), Int32(derivedKeyLen), derivedKey) + if status != 1 { + let error = ERR_get_error() + + throw CryptorError.fail(Int32(error), "ERROR: PKCS5_PBKDF2_HMAC failed, reason: \(errToString(ERR_error_string(error, nil)))") + } + #else let status: Int32 = CCKeyDerivationPBKDF(CCPBKDFAlgorithm(kCCPBKDF2), password, passwordLen, salt, saltLen, prf.nativeValue(), rounds, derivedKey, derivedKeyLen) if status != Int32(kCCSuccess) { throw CryptorError.fail(status, "ERROR: CCKeyDerivationPBDK failed with status \(status).") } - #elseif os(Linux) - let status = PKCS5_PBKDF2_HMAC(password, Int32(passwordLen), salt, Int32(saltLen), Int32(rounds), .make(optional: prf.nativeValue()), Int32(derivedKeyLen), derivedKey) - if status != 1 { - let error = ERR_get_error() - - throw CryptorError.fail(Int32(error), "ERROR: PKCS5_PBKDF2_HMAC failed, reason: \(errToString(ERR_error_string(error, nil)))") - } #endif } } diff --git a/Sources/Cryptor/Random.swift b/Sources/Cryptor/Random.swift index 33266c6..1be8caf 100755 --- a/Sources/Cryptor/Random.swift +++ b/Sources/Cryptor/Random.swift @@ -17,10 +17,10 @@ import Foundation -#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) +#if os(Linux) + import OpenSSL +#else import CommonCrypto -#elseif os(Linux) - import OpenSSL #endif public typealias RNGStatus = Status @@ -41,20 +41,20 @@ public class Random { /// public class func generate(bytes: UnsafeMutablePointer, byteCount: Int) -> RNGStatus { - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + let statusCode = RAND_bytes(bytes, Int32(byteCount)) + if statusCode != 1 { + + let errCode = ERR_get_error() + return Status.rngFailure(errCode) + } + return Status.success + #else let statusCode = CCRandomGenerateBytes(bytes, byteCount) guard let status = Status(rawValue: statusCode) else { fatalError("CCRandomGenerateBytes returned unexpected status code: \(statusCode)") } return status - #elseif os(Linux) - let statusCode = RAND_bytes(bytes, Int32(byteCount)) - if statusCode != 1 { - - let errCode = ERR_get_error() - return Status.rngFailure(errCode) - } - return Status.success #endif } diff --git a/Sources/Cryptor/Status.swift b/Sources/Cryptor/Status.swift index be87926..954e683 100755 --- a/Sources/Cryptor/Status.swift +++ b/Sources/Cryptor/Status.swift @@ -17,13 +17,111 @@ import Foundation -#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) - import CommonCrypto -#elseif os(Linux) - import OpenSSL +#if os(Linux) + import OpenSSL +#else + import CommonCrypto #endif -#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) +#if os(Linux) + +/// +/// Error status +/// +public enum Status: Swift.Error, CustomStringConvertible { + + /// Success + case success + + /// Unimplemented with reason + case unimplemented(String) + + /// Not supported with reason + case notSupported(String) + + /// Parameter Error + case paramError + + /// Failure with error code + case fail(UInt) + + /// Random Byte Generator Failure with error code + case rngFailure(UInt) + + /// The error code itself + public var code: Int { + + switch self { + + case .success: + return 0 + + case .notSupported: + return -1 + + case .unimplemented: + return -2 + + case .paramError: + return -3 + + case .fail(let code): + return Int(code) + + case .rngFailure(let code): + return Int(code) + } + } + + /// + /// Create enum value from raw `SSL error code` value. + /// + public static func fromRaw(status: UInt) -> Status? { + + return Status.fail(status) + } + + /// + /// Obtain human-readable string for the error code. + /// + public var description: String { + + switch self { + + case .success: + return "No error" + + case .notSupported(let reason): + return "Not supported: \(reason)" + + case .unimplemented(let reason): + return "Not implemented: \(reason)" + + case .paramError: + return "Invalid parameters passed" + + case .fail(let errorCode): + return "ERROR: code: \(errorCode), reason: \(errToString(ERR_error_string(UInt(errorCode), nil)))" + + case .rngFailure(let errorCode): + return "Random Byte Generator ERROR: code: \(errorCode), reason: \(errToString(ERR_error_string(UInt(errorCode), nil)))" + } + } +} + +// MARK: Operators + +func == (lhs: Status, rhs: Status) -> Bool { + + return lhs.code == rhs.code +} + +func != (lhs: Status, rhs: Status) -> Bool { + + return lhs.code != rhs.code +} + +#else /// /// Links the native CommonCryptoStatus enumeration to Swift versions. /// @@ -129,104 +227,6 @@ public enum Status: CCCryptorStatus, Swift.Error, CustomStringConvertible { } } -#elseif os(Linux) - -/// -/// Error status -/// -public enum Status: Swift.Error, CustomStringConvertible { - - /// Success - case success - - /// Unimplemented with reason - case unimplemented(String) - - /// Not supported with reason - case notSupported(String) - - /// Parameter Error - case paramError - - /// Failure with error code - case fail(UInt) - - /// Random Byte Generator Failure with error code - case rngFailure(UInt) - - /// The error code itself - public var code: Int { - - switch self { - - case .success: - return 0 - - case .notSupported: - return -1 - - case .unimplemented: - return -2 - - case .paramError: - return -3 - - case .fail(let code): - return Int(code) - - case .rngFailure(let code): - return Int(code) - } - } - - /// - /// Create enum value from raw `SSL error code` value. - /// - public static func fromRaw(status: UInt) -> Status? { - - return Status.fail(status) - } - - /// - /// Obtain human-readable string for the error code. - /// - public var description: String { - - switch self { - - case .success: - return "No error" - - case .notSupported(let reason): - return "Not supported: \(reason)" - - case .unimplemented(let reason): - return "Not implemented: \(reason)" - - case .paramError: - return "Invalid parameters passed" - - case .fail(let errorCode): - return "ERROR: code: \(errorCode), reason: \(errToString(ERR_error_string(UInt(errorCode), nil)))" - - case .rngFailure(let errorCode): - return "Random Byte Generator ERROR: code: \(errorCode), reason: \(errToString(ERR_error_string(UInt(errorCode), nil)))" - } - } -} - -// MARK: Operators - -func == (lhs: Status, rhs: Status) -> Bool { - - return lhs.code == rhs.code -} - -func != (lhs: Status, rhs: Status) -> Bool { - - return lhs.code != rhs.code -} - #endif /// diff --git a/Sources/Cryptor/StreamCryptor.swift b/Sources/Cryptor/StreamCryptor.swift index f951d36..599712c 100755 --- a/Sources/Cryptor/StreamCryptor.swift +++ b/Sources/Cryptor/StreamCryptor.swift @@ -17,10 +17,10 @@ import Foundation -#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) - import CommonCrypto -#elseif os(Linux) - import OpenSSL +#if os(Linux) + import OpenSSL +#else + import CommonCrypto #endif /// @@ -74,7 +74,22 @@ public class StreamCryptor { /// Decrypting case decrypt - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + + /// Convert to native value + func nativeValue() -> UInt32 { + + switch self { + + case .encrypt: + return 0 + + case .decrypt: + return 1 + } + } + + #else /// Convert to native `CCOperation` func nativeValue() -> CCOperation { @@ -89,21 +104,6 @@ public class StreamCryptor { } } - #elseif os(Linux) - - /// Convert to native value - func nativeValue() -> UInt32 { - - switch self { - - case .encrypt: - return 0 - - case .decrypt: - return 1 - } - } - #endif } @@ -187,7 +187,15 @@ public class StreamCryptor { /// No options public static let none = Options([]) - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + + /// Use padding. Needed unless the input is a integral number of blocks long. + public static var pkcs7Padding = Options(rawValue:0x0001) + + /// Electronic Code Book Mode. Don't use this. + public static var ecbMode = Options(rawValue:0x0002) + + #else /// Use padding. Needed unless the input is a integral number of blocks long. public static var pkcs7Padding = Options(rawValue:kCCOptionPKCS7Padding) @@ -195,14 +203,6 @@ public class StreamCryptor { /// Electronic Code Book Mode. Don't use this. public static var ecbMode = Options(rawValue:kCCOptionECBMode) - #elseif os(Linux) - - /// Use padding. Needed unless the input is a integral number of blocks long. - public static var pkcs7Padding = Options(rawValue:0x0001) - - /// Electronic Code Book Mode. Don't use this. - public static var ecbMode = Options(rawValue:0x0002) - #endif } @@ -285,7 +285,75 @@ public class StreamCryptor { } } - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + + /// Native, OpenSSL function for algorithm. + func nativeValue(options: Options) -> OpaquePointer? { + + if options == .pkcs7Padding || options == .none { + + switch self { + + case .aes, .aes128: + return .init(EVP_aes_128_cbc()) + + case .aes192: + return .init(EVP_aes_192_cbc()) + + case .aes256: + return .init(EVP_aes_256_cbc()) + + case .des: + return .init(EVP_des_cbc()) + + case .tripleDes: + return .init(EVP_des_ede3_cbc()) + + case .cast: + return .init(EVP_cast5_cbc()) + + case .rc2: + return .init(EVP_rc2_cbc()) + + case .blowfish: + return .init(EVP_bf_cbc()) + } + } + + if options == .ecbMode { + + switch self { + + case .aes, .aes128: + return .init(EVP_aes_128_ecb()) + + case .aes192: + return .init(EVP_aes_192_ecb()) + + case .aes256: + return .init(EVP_aes_256_ecb()) + + case .des: + return .init(EVP_des_ecb()) + + case .tripleDes: + return .init(EVP_des_ede3_ecb()) + + case .cast: + return .init(EVP_cast5_ecb()) + + case .rc2: + return .init(EVP_rc2_ecb()) + + case .blowfish: + return .init(EVP_bf_ecb()) + } + } + + fatalError("Unsupported options and/or algorithm.") + } + + #else /// Native, CommonCrypto constant for algorithm. func nativeValue() -> CCAlgorithm { @@ -312,74 +380,6 @@ public class StreamCryptor { } } - #elseif os(Linux) - - /// Native, OpenSSL function for algorithm. - func nativeValue(options: Options) -> OpaquePointer? { - - if options == .pkcs7Padding || options == .none { - - switch self { - - case .aes, .aes128: - return .init(EVP_aes_128_cbc()) - - case .aes192: - return .init(EVP_aes_192_cbc()) - - case .aes256: - return .init(EVP_aes_256_cbc()) - - case .des: - return .init(EVP_des_cbc()) - - case .tripleDes: - return .init(EVP_des_ede3_cbc()) - - case .cast: - return .init(EVP_cast5_cbc()) - - case .rc2: - return .init(EVP_rc2_cbc()) - - case .blowfish: - return .init(EVP_bf_cbc()) - } - } - - if options == .ecbMode { - - switch self { - - case .aes, .aes128: - return .init(EVP_aes_128_ecb()) - - case .aes192: - return .init(EVP_aes_192_ecb()) - - case .aes256: - return .init(EVP_aes_256_ecb()) - - case .des: - return .init(EVP_des_ecb()) - - case .tripleDes: - return .init(EVP_des_ede3_ecb()) - - case .cast: - return .init(EVP_cast5_ecb()) - - case .rc2: - return .init(EVP_rc2_ecb()) - - case .blowfish: - return .init(EVP_bf_ecb()) - } - } - - fatalError("Unsupported options and/or algorithm.") - } - #endif /// @@ -389,7 +389,36 @@ public class StreamCryptor { /// func validKeySize() -> ValidKeySize { - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + + switch self { + + case .aes, .aes128: + return .fixed(kCCKeySizeAES128) + + case .aes192: + return .fixed(kCCKeySizeAES192) + + case .aes256: + return .fixed(kCCKeySizeAES256) + + case .des: + return .fixed(kCCKeySizeDES) + + case .tripleDes: + return .fixed(kCCKeySize3DES) + + case .cast: + return .range(kCCKeySizeMinCAST, kCCKeySizeMaxCAST) + + case .rc2: + return .range(kCCKeySizeMinRC2, kCCKeySizeMaxRC2) + + case .blowfish: + return .range(kCCKeySizeMinBlowfish, kCCKeySizeMaxBlowfish) + } + + #else switch self { @@ -412,35 +441,6 @@ public class StreamCryptor { return .range(kCCKeySizeMinBlowfish, kCCKeySizeMaxBlowfish) } - #elseif os(Linux) - - switch self { - - case .aes, .aes128: - return .fixed(kCCKeySizeAES128) - - case .aes192: - return .fixed(kCCKeySizeAES192) - - case .aes256: - return .fixed(kCCKeySizeAES256) - - case .des: - return .fixed(kCCKeySizeDES) - - case .tripleDes: - return .fixed(kCCKeySize3DES) - - case .cast: - return .range(kCCKeySizeMinCAST, kCCKeySizeMaxCAST) - - case .rc2: - return .range(kCCKeySizeMinRC2, kCCKeySizeMaxRC2) - - case .blowfish: - return .range(kCCKeySizeMinBlowfish, kCCKeySizeMaxBlowfish) - } - #endif } @@ -478,22 +478,22 @@ public class StreamCryptor { /// private var haveContext: Bool = false - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + + /// OpenSSL Cipher Context + private let context: OpaquePointer? = .init(EVP_CIPHER_CTX_new()) + + /// Operation + private var operation: Operation = .encrypt + + /// The algorithm + private var algorithm: Algorithm + + #else /// CommonCrypto Context private var context = UnsafeMutablePointer.allocate(capacity: 1) - #elseif os(Linux) - - /// OpenSSL Cipher Context - private let context: OpaquePointer? = .init(EVP_CIPHER_CTX_new()) - - /// Operation - private var operation: Operation = .encrypt - - /// The algorithm - private var algorithm: Algorithm - #endif @@ -522,7 +522,47 @@ public class StreamCryptor { throw CryptorError.invalidIVSizeOrLength } - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + + self.algorithm = algorithm + self.operation = operation + + var rawStatus: Int32 + + switch self.operation { + + case .encrypt: + rawStatus = EVP_EncryptInit_ex(.make(optional: self.context), .make(optional: algorithm.nativeValue(options: options)), nil, keyBuffer, ivBuffer) + + case .decrypt: + rawStatus = EVP_DecryptInit_ex(.make(optional: self.context), .make(optional: algorithm.nativeValue(options: options)), nil, keyBuffer, ivBuffer) + } + + if rawStatus == 0 { + + let errorCode = ERR_get_error() + if let status = Status.fromRaw(status: errorCode) { + self.status = status + } else { + + throw CryptorError.fail(Int32(errorCode), "Cryptor init returned unexpected status.") + } + } + + self.haveContext = true + + // Default to no padding... + var needPadding: Int32 = 0 + if options == .pkcs7Padding { + needPadding = 1 + } + + // Note: This call must be AFTER the init call above... + EVP_CIPHER_CTX_set_padding(.make(optional: self.context), needPadding) + + self.status = Status.success + + #else let rawStatus = CCCryptorCreate(operation.nativeValue(), algorithm.nativeValue(), CCOptions(options.rawValue), keyBuffer, keyByteCount, ivBuffer, self.context) @@ -537,46 +577,6 @@ public class StreamCryptor { self.haveContext = true - #elseif os(Linux) - - self.algorithm = algorithm - self.operation = operation - - var rawStatus: Int32 - - switch self.operation { - - case .encrypt: - rawStatus = EVP_EncryptInit_ex(.make(optional: self.context), .make(optional: algorithm.nativeValue(options: options)), nil, keyBuffer, ivBuffer) - - case .decrypt: - rawStatus = EVP_DecryptInit_ex(.make(optional: self.context), .make(optional: algorithm.nativeValue(options: options)), nil, keyBuffer, ivBuffer) - } - - if rawStatus == 0 { - - let errorCode = ERR_get_error() - if let status = Status.fromRaw(status: errorCode) { - self.status = status - } else { - - throw CryptorError.fail(Int32(errorCode), "Cryptor init returned unexpected status.") - } - } - - self.haveContext = true - - // Default to no padding... - var needPadding: Int32 = 0 - if options == .pkcs7Padding { - needPadding = 1 - } - - // Note: This call must be AFTER the init call above... - EVP_CIPHER_CTX_set_padding(.make(optional: self.context), needPadding) - - self.status = Status.success - #endif } @@ -644,7 +644,12 @@ public class StreamCryptor { return } - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + + EVP_CIPHER_CTX_free(.make(optional: self.context)) + self.haveContext = false + + #else // Ensure we've got a context before attempting to get rid of it... if self.context.pointee == nil { @@ -664,17 +669,8 @@ public class StreamCryptor { fatalError("CCCryptorUpdate returned unexpected status.") } - #if swift(>=4.1) - context.deallocate() - #else - context.deallocate(capacity: 1) - #endif - - self.haveContext = false - - #elseif os(Linux) - - EVP_CIPHER_CTX_free(.make(optional: self.context)) + context.deallocate() + self.haveContext = false #endif @@ -695,15 +691,9 @@ public class StreamCryptor { let dataOutAvailable = byteArrayOut.count var dataOutMoved = 0 - #if swift(>=5.0) - dataIn.withUnsafeBytes() { - _ = update(bufferIn: $0.baseAddress!, byteCountIn: dataIn.count, bufferOut: &byteArrayOut, byteCapacityOut: dataOutAvailable, byteCountOut: &dataOutMoved) - } - #else - dataIn.withUnsafeBytes() { (buffer: UnsafePointer) in - _ = update(bufferIn: buffer, byteCountIn: dataIn.count, bufferOut: &byteArrayOut, byteCapacityOut: dataOutAvailable, byteCountOut: &dataOutMoved) - } - #endif + dataIn.withUnsafeBytes() { + _ = update(bufferIn: $0.baseAddress!, byteCountIn: dataIn.count, bufferOut: &byteArrayOut, byteCapacityOut: dataOutAvailable, byteCountOut: &dataOutMoved) + } return (dataOutMoved, self.status) } @@ -798,7 +788,37 @@ public class StreamCryptor { if self.status == .success { - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + + var rawStatus: Int32 + var outLength: Int32 = 0 + + switch self.operation { + + case .encrypt: + rawStatus = EVP_EncryptUpdate(.make(optional: self.context), bufferOut, &outLength, bufferIn.assumingMemoryBound(to: UInt8.self), Int32(byteCountIn)) + + case .decrypt: + rawStatus = EVP_DecryptUpdate(.make(optional: self.context), bufferOut, &outLength, bufferIn.assumingMemoryBound(to: UInt8.self), Int32(byteCountIn)) + } + + byteCountOut = Int(outLength) + + if rawStatus == 0 { + + let errorCode = ERR_get_error() + if let status = Status.fromRaw(status: errorCode) { + self.status = status + } else { + fatalError("Cryptor update returned unexpected status.") + } + + } else { + + self.status = Status.success + } + + #else let rawStatus = CCCryptorUpdate(self.context.pointee, bufferIn, byteCountIn, bufferOut, byteCapacityOut, &byteCountOut) if let status = Status.fromRaw(status: rawStatus) { @@ -807,36 +827,6 @@ public class StreamCryptor { fatalError("CCCryptorUpdate returned unexpected status.") } - #elseif os(Linux) - - var rawStatus: Int32 - var outLength: Int32 = 0 - - switch self.operation { - - case .encrypt: - rawStatus = EVP_EncryptUpdate(.make(optional: self.context), bufferOut, &outLength, bufferIn.assumingMemoryBound(to: UInt8.self), Int32(byteCountIn)) - - case .decrypt: - rawStatus = EVP_DecryptUpdate(.make(optional: self.context), bufferOut, &outLength, bufferIn.assumingMemoryBound(to: UInt8.self), Int32(byteCountIn)) - } - - byteCountOut = Int(outLength) - - if rawStatus == 0 { - - let errorCode = ERR_get_error() - if let status = Status.fromRaw(status: errorCode) { - self.status = status - } else { - fatalError("Cryptor update returned unexpected status.") - } - - } else { - - self.status = Status.success - } - #endif } @@ -864,7 +854,37 @@ public class StreamCryptor { if self.status == Status.success { - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + + var rawStatus: Int32 + var outLength: Int32 = Int32(byteCapacityOut) + + switch self.operation { + + case .encrypt: + rawStatus = EVP_EncryptFinal_ex(.make(optional: self.context), bufferOut, &outLength) + + case .decrypt: + rawStatus = EVP_DecryptFinal_ex(.make(optional: self.context), bufferOut, &outLength) + } + + byteCountOut = Int(outLength) + + if rawStatus == 0 { + + let errorCode = ERR_get_error() + if let status = Status.fromRaw(status: errorCode) { + self.status = status + } else { + fatalError("Cryptor final returned unexpected status.") + } + + } else { + + self.status = Status.success + } + + #else let rawStatus = CCCryptorFinal(self.context.pointee, bufferOut, byteCapacityOut, &byteCountOut) if let status = Status.fromRaw(status: rawStatus) { @@ -873,36 +893,6 @@ public class StreamCryptor { fatalError("CCCryptorUpdate returned unexpected status.") } - #elseif os(Linux) - - var rawStatus: Int32 - var outLength: Int32 = Int32(byteCapacityOut) - - switch self.operation { - - case .encrypt: - rawStatus = EVP_EncryptFinal_ex(.make(optional: self.context), bufferOut, &outLength) - - case .decrypt: - rawStatus = EVP_DecryptFinal_ex(.make(optional: self.context), bufferOut, &outLength) - } - - byteCountOut = Int(outLength) - - if rawStatus == 0 { - - let errorCode = ERR_get_error() - if let status = Status.fromRaw(status: errorCode) { - self.status = status - } else { - fatalError("Cryptor final returned unexpected status.") - } - - } else { - - self.status = Status.success - } - #endif } @@ -921,18 +911,18 @@ public class StreamCryptor { /// public func getOutputLength(inputByteCount: Int, isFinal: Bool = false) -> Int { - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + + if inputByteCount == 0 { + return self.algorithm.blockSize + } + + return (inputByteCount + self.algorithm.blockSize - (inputByteCount % self.algorithm.blockSize)) + + #else return CCCryptorGetOutputLength(self.context.pointee, inputByteCount, isFinal) - #elseif os(Linux) - - if inputByteCount == 0 { - return self.algorithm.blockSize - } - - return (inputByteCount + self.algorithm.blockSize - (inputByteCount % self.algorithm.blockSize)) - #endif } diff --git a/Sources/Cryptor/Updatable.swift b/Sources/Cryptor/Updatable.swift index 3355830..8548fdf 100755 --- a/Sources/Cryptor/Updatable.swift +++ b/Sources/Cryptor/Updatable.swift @@ -64,17 +64,9 @@ extension Updatable { /// public func update(data: Data) -> Self? { - #if swift(>=5.0) - data.withUnsafeBytes() { - - _ = update(from: $0.baseAddress!, byteCount: size_t(data.count)) - } - #else - _ = data.withUnsafeBytes() { (buffer: UnsafePointer) in - - _ = update(from: buffer, byteCount: size_t(data.count)) - } - #endif + data.withUnsafeBytes() { + _ = update(from: $0.baseAddress!, byteCount: size_t(data.count)) + } return self.status == .success ? self : nil } diff --git a/Sources/Cryptor/Utilities.swift b/Sources/Cryptor/Utilities.swift index 835c934..4d7c0b0 100755 --- a/Sources/Cryptor/Utilities.swift +++ b/Sources/Cryptor/Utilities.swift @@ -206,11 +206,11 @@ public struct CryptoUtils { public static func hexNSString(from byteArray: [UInt8], uppercase: Bool = false) -> NSString { let formatString = (uppercase) ? "%02X" : "%02x" - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if os(Linux) + let aString = byteArray.map() { String(format: formatString, $0) }.reduce("", +) + return NSString(string: aString) + #else return byteArray.map() { String(format: formatString, $0) }.reduce("", +) as NSString - #else - let aString = byteArray.map() { String(format: formatString, $0) }.reduce("", +) - return NSString(string: aString) #endif } diff --git a/Tests/CryptorTests/CryptorTests.swift b/Tests/CryptorTests/CryptorTests.swift index f63743d..d633836 100644 --- a/Tests/CryptorTests/CryptorTests.swift +++ b/Tests/CryptorTests/CryptorTests.swift @@ -19,10 +19,10 @@ import XCTest import Foundation @testable import Cryptor -#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) - import CommonCrypto -#elseif os(Linux) - import OpenSSL +#if os(Linux) + import OpenSSL +#else + import CommonCrypto #endif import Dispatch @@ -216,7 +216,7 @@ class CryptorTests: XCTestCase { let cryptor = try Cryptor(operation:.encrypt, algorithm:.aes, options:.ecbMode, key:key, iv:Array()) let cipherText = cryptor.update(byteArray: plainText)?.final() XCTAssert(cipherText == nil, "Expected nil cipherText") - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if !os(Linux) XCTAssertEqual(cryptor.status, Status.alignmentError, "Expected AlignmentError") #endif } catch let error { @@ -761,7 +761,7 @@ class CryptorTests: XCTestCase { // MARK: - Status func test_Status() { - #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + #if !os(Linux) // These are only for CommonCrypto... XCTAssertEqual(Status.success.toRaw(), CCCryptorStatus(kCCSuccess)) diff --git a/Tests/CryptorTests/Info.plist b/Tests/CryptorTests/Info.plist deleted file mode 100644 index ba72822..0000000 --- a/Tests/CryptorTests/Info.plist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - -