0

Context: I want to create a simple Swift command line tool using CryptoSwift I am relatively new to Xcode and Swift (and MacOS!).

Configuration:
- MacOS High Sierra 10.13.2
- Xcode: 9.2

Steps:

  1. I start Xcode
  2. Create a new project “Command Line tool” for MacOS
  3. Option for my project:
    • Product name: cryptodemo
    • Organisation Identifier: com.demo
    • Language Swift
  4. I create the project into ~/Documents
  5. Fill my main.swift with:

    import Foundation
    import CryptoSwift
    
    print("Hello, World!")
    
    let bytes:Array<UInt8> = [0x01, 0x02, 0x03]
    let digest = Digest.md5(bytes)
    
  6. Open the shell and go into ~/Documents/cryptodemo

  7. Add CryptoSwift as a submodule as defined by the project’s README using: git submodule add https://github.com/krzyzanowskim/CryptoSwift.git
  8. Open Finder and drag the CryptoSwift.xcodeproj file into my Xcode project
  9. In Xcode, I go into my project Build Phase

    • I added CryptoSwift as a target dependency
    • I added CryptoSwift.framework to Link Binaries with Libraries
    • I added CryptoSwift.framework to Copy Files with:
      • Destination: Framework
      • SubPath: (empty) enter image description here
  10. Then I build it. I have this error:

    Check dependencies
    
    Unable to run command 'PBXCp CryptoSwift.framework' - this target might include its own product.
    Unable to run command 'CodeSign A' - this target might include its own product.
    

    enter image description here

Here is the archive of the project cryptodemo.zip

Marcin
  • 3,694
  • 5
  • 32
  • 52
OlivierM
  • 2,820
  • 24
  • 41
  • I couldn't download your project using the link you post. Why not adding the dependency using CocoaPods, Carthage or Swift Package Manager? It would be easier for you and also has the advantage that is easier to update the library in the future instead of doing it manually. Here you can check the installation of CocoaPods: https://guides.cocoapods.org/using/getting-started.html#getting-started – omarzl Jan 16 '18 at 17:32
  • You need to click on "Valider et telecharger le fichier" (I also had a Gateway Timeout issue and tried again and it worked). A similar project is also available here: https://github.com/krzyzanowskim/CryptoSwift/files/1610314/demo.zip I actually discovered Swift Package manager a couple of hours ago and went through this way. But I would still like to understand what is the issue in this project. – OlivierM Jan 16 '18 at 17:39
  • It is best to avoid using CryptoSwift, amoung other things it is 500 to 1000 times slower than Common Crypto based implementations. Apple's Common Crypto is FIPS certified and as such has been well vetted, using CryptoSwift is taking a chance on correctness and security such as timing and power attacks. – zaph Feb 07 '18 at 04:12

2 Answers2

0

Delete step 9 and add CryptoSwift.framework to the "Linked Frameworks and Libraries"

enter image description here

Like here: enter image description here

Marcin
  • 3,694
  • 5
  • 32
  • 52
0

The only way I managed to build a command line tool using a third-party Swift libraries is to use Swift Package Manager (SPM).

Example of Swift project using SPM (that could be generated using swift package init --type executable):

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: “mytool”,
    dependencies: [
        .package(url: "https://github.com/myfreeweb/SwiftCBOR.git", .branch("master")),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: “mytool”,
            dependencies: [ "SwiftCBOR" ]),
    ]
)

A Xcode project could be generated from this SPM using: swift package generate-xcodeproj

OlivierM
  • 2,820
  • 24
  • 41