Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Xcode 10.0 and Swift 4.2 #7

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9eeef6f
Small update to podspec
ziogaschr Apr 13, 2015
744e58b
Add support for Swift 2.1
ziogaschr Nov 4, 2015
d3c9312
verify_content() throws the appropriate error
ziogaschr Nov 5, 2015
f082c88
Add Bridging Header info
ziogaschr Nov 5, 2015
278b120
Update .gitignore
ziogaschr Nov 5, 2015
808e826
Remove Common Crypto module-map
ziogaschr Nov 5, 2015
4b0d6dd
Handle mandatory fields
ziogaschr May 30, 2016
def3567
Make `verify_content` public
ziogaschr May 30, 2016
2c67cea
Podspec separates `ed25519` to a new subspec
ziogaschr May 30, 2016
fcec822
Better example playground
ziogaschr May 30, 2016
40c8e99
Upgrade project for latest Xcode
ziogaschr May 30, 2016
2f938d8
Add installation instructions to Readme
ziogaschr May 30, 2016
fb649e4
Add Swift 3 support
ziogaschr Nov 15, 2016
d266c7f
Add a required init so as lib can be used in Swift Generics
ziogaschr Feb 23, 2017
baa37c3
Fix base64 encode/decode
ziogaschr Mar 3, 2017
bae5d89
Fix base64 encode/decode
ziogaschr Mar 3, 2017
9e09b46
Fix for Xcode 8.3
ziogaschr Apr 5, 2017
2a8b32b
Update code for latest version of Sodium
ziogaschr Apr 5, 2017
369be30
Migrate code for Xcode 9 Beta 6
ziogaschr Sep 6, 2017
717a726
Update for latest Sodium version
ziogaschr Sep 15, 2017
abd0892
Migrate String.characters for Xcode9.1
ziogaschr Oct 8, 2017
9195d3b
Fix dumps method with a String key
ziogaschr Mar 23, 2018
d5858f3
Revert Fix dumps method with a String key
ziogaschr Apr 3, 2018
28f5fd6
Upgrade code for Xcode10.0
ziogaschr Sep 15, 2018
b28f7a8
Make Sodium dependency to use master branch as Podfile in registry is…
ziogaschr Sep 16, 2018
d8c7af1
Make Sodium dependency to use latest version as Podfile in registry i…
ziogaschr Sep 16, 2018
19cd6cb
Cleanup Podfile
ziogaschr Sep 16, 2018
75ce418
Remove note for bridging header for CommonCrypto
ziogaschr Sep 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# Xcode
#
build/
*.pbxuser
!default.pbxuser

# Exclude the build directory
build/*

# Exclude temp nibs and swap files
*~.nib
*.swp

# Exclude OS X folder attributes
.DS_Store

# Exclude user-specific XCode 3 and 4 files
*.mode1
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspective
*.perspectivev3
!default.perspectivev3
*.pbxuser
*.xcworkspace
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate


# CocoaPods
#
Expand Down
28 changes: 28 additions & 0 deletions Build-Phases/common-crypto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Credits to @radianttap https://github.com/radianttap/JSONWebToken.swift/blob/master/LICENSE

COMMON_CRYPTO_DIR="${SDKROOT}/usr/include/CommonCrypto"
if [ -f "${COMMON_CRYPTO_DIR}/module.modulemap" ]
then
echo "CommonCrypto already exists, skipping"
else
# This if-statement means we'll only run the main script if the
# CommonCrypto.framework directory doesn't exist because otherwise
# the rest of the script causes a full recompile for anything
# where CommonCrypto is a dependency
# Do a "Clean Build Folder" to remove this directory and trigger
# the rest of the script to run
FRAMEWORK_DIR="${BUILT_PRODUCTS_DIR}/CommonCrypto.framework"

if [ -d "${FRAMEWORK_DIR}" ]; then
echo "${FRAMEWORK_DIR} already exists, so skipping the rest of the script."
exit 0
fi

mkdir -p "${FRAMEWORK_DIR}/Modules"
echo "module CommonCrypto [system] {
header \"${SDKROOT}/usr/include/CommonCrypto/CommonCrypto.h\"
export *
}" >> "${FRAMEWORK_DIR}/Modules/module.modulemap"

ln -sf "${SDKROOT}/usr/include/CommonCrypto" "${FRAMEWORK_DIR}/Headers"
fi
5 changes: 1 addition & 4 deletions JWT workspace.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "D13A0161F3961F3380472D7F6128C9B2159DADA6",
"DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : {

},
"DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : {
"D13A0161F3961F3380472D7F6128C9B2159DADA6" : 0,
"CD87797B9D09AEEE7FEB1D43B38DA32D51BC7F68" : 0
},
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "FC5C1AE1-1DF3-43CF-89D3-D0C72142FD62",
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
"D13A0161F3961F3380472D7F6128C9B2159DADA6" : "swift-jwt\/",
"CD87797B9D09AEEE7FEB1D43B38DA32D51BC7F68" : "swift-sodium\/"
},
"DVTSourceControlWorkspaceBlueprintNameKey" : "JWT workspace",
"DVTSourceControlWorkspaceBlueprintVersion" : 204,
"DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "JWT workspace.xcworkspace",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [
{
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:ziogaschr\/swift-sodium.git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "CD87797B9D09AEEE7FEB1D43B38DA32D51BC7F68"
},
{
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:stannie\/swift-jwt.git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "D13A0161F3961F3380472D7F6128C9B2159DADA6"
}
]
}
79 changes: 79 additions & 0 deletions JWT-Playground.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*:
### Table of Contents

1. [HS256 Load](HS256 Load)
2. [HS256 Dump](HS256 Dump)
3. [Ed25519 Dump](Ed25519 Dump)
*/

import SwiftJWT

/*:
### HS256 Load
Example: load a HS256 signed JWT from a string, and generate a new one with a new password
*/

let jwt_str = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6InBob25lIiwicGhvbmVfbnVtYmVyIjoiKzE2NTAyODU1NjAwIiwidHlwZSI6ImxhbmRsaW5lIiwiYXVkIjoiaHR0cHM6Ly9hdXRoZW50aXEuY29tIn0.CAqNpbmOA9lz9aq7Sp1NqqbdLJARmFKY3L7CKcgXLNU"

var jwt = JWT(algorithms: ["none", "HS256"])

do {
try jwt.loads(jwt_str, key: "secret")
print(jwt.header)
print(jwt.body)

let new_jwt = try jwt.dumps("geheim")

assert(jwt_str != new_jwt)

} catch {
print(error)
print("Validate of SignedJWT failed")
}


/*:
### HS256 Dump
Example: dump a HS256 signed JWT from a dictionary
*/

jwt = JWT(header: ["alg":"HS256"],
body: [
"sub": "1234567890",
"name": "John Doe",
"admin": true
], algorithms: nil)

do {
print(try jwt.dumps("secret"))

} catch {
print(error)
print("Validate of SignedJWT failed")
}


/*:
### Ed25519 Load
Example: load an Ed25519 signed JWT from a string
*/

let jwt_ed = "eyJhbGciOiJFZDI1NTE5IiwidHlwIjoiSldUIiwia2lkIjoiWE43VnBFWDF1Q3h4aHZ3VXVhY1lodVU5dDZ1eGdMYWhSaUxlU0VIRU5payJ9.eyJmb28iOiJiYXIifQ.a2dDcKXByKxiouOLnXUm7YUKHMGOU3yn_g91C90e8YmKjlF1_9ylAKukfMm6Y6WS3dZp2ysaglzzTnVxnRYyDQ"
let sk = "YHWUUc0P6SY46WaDdnssE8NpFsQQxJrvmdOrpU9X0wU"
let pk = "XN7VpEX1uCxxhvwUuacYhuU9t6uxgLahRiLeSEHENik"


jwt = JWTNaCl(algorithms: ["Ed25519"])

do {
try jwt.loads(jwt_ed, verify: false, mandatory: ["foo"])

print(jwt.header)
print(jwt.body)

} catch {
print(error)
print("Validate of SignedJWT failed")
}


27 changes: 0 additions & 27 deletions JWT-Playground.playground/section-1.swift

This file was deleted.

19 changes: 0 additions & 19 deletions JWT/CommonCrypto/CommonCrypto.h

This file was deleted.

15 changes: 0 additions & 15 deletions JWT/CommonCrypto/CommonCrypto.xcconfig

This file was deleted.

26 changes: 0 additions & 26 deletions JWT/CommonCrypto/Info.plist

This file was deleted.

4 changes: 0 additions & 4 deletions JWT/CommonCrypto/iphoneos.modulemap

This file was deleted.

4 changes: 0 additions & 4 deletions JWT/CommonCrypto/iphonesimulator.modulemap

This file was deleted.

4 changes: 0 additions & 4 deletions JWT/CommonCrypto/macosx.modulemap

This file was deleted.

36 changes: 0 additions & 36 deletions JWT/CommonCryptoTests/CommonCryptoTests.swift

This file was deleted.

24 changes: 0 additions & 24 deletions JWT/CommonCryptoTests/Info.plist

This file was deleted.

24 changes: 24 additions & 0 deletions JWT/JWT/Extensions/Data+JWT.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// NSData+JWT.swift
// SwiftJWT
//
// Created by Chris Ziogas on 05/11/15.
// Copyright © 2015 RoundZero bv. All rights reserved.
//

import Foundation

extension Data {
// MARK: - base64 extensions
func base64SafeUrlEncode(_ options: Data.Base64EncodingOptions = []) -> String {
// regular base64 encoding
var s = self.base64EncodedString(options: options)

// s = s.substringToIndex(s.endIndex.predecessor()) // remove last char
s = s.replacingOccurrences(of: "=", with: "") // Remove any trailing '='s
s = s.replacingOccurrences(of: "+", with: "-") // 62nd char of encoding
s = s.replacingOccurrences(of: "/", with: "_") // 63rd char of encoding

return s
}
}
Loading