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

Move CommonCrypto and zlib dependencies mapping to custom module map #520

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"object": {
"pins": [
{
"package": "SSCommonCrypto",
"repositoryURL": "https://github.com/daltoniam/common-crypto-spm",
"state": {
"branch": null,
"revision": "2eb3aff0fb57f92f5722fac5d6d20bf64669ca66",
"version": "1.1.0"
}
},
{
"package": "SSCZLib",
"repositoryURL": "https://github.com/daltoniam/zlib-spm.git",
"state": {
"branch": null,
"revision": "83ac8d719a2f3aa775dbdf116a57f56fb2c49abb",
"version": "1.1.0"
}
}
]
},
"version": 1
}
19 changes: 12 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// swift-tools-version:4.0

//
// Package.Swift
// Starscream
Expand All @@ -21,12 +23,15 @@
import PackageDescription

let package = Package(
name: "Starscream",
dependencies: [
.Package(url: "https://github.com/daltoniam/zlib-spm.git",
majorVersion: 1, minor: 1),
.Package(url: "https://github.com/daltoniam/common-crypto-spm",
majorVersion: 1, minor: 1),
name: "Starscream",
products: [
.library(name: "Starscream", targets: ["Starscream"])
],
dependencies: [
.package(url: "https://github.com/daltoniam/zlib-spm.git", from: "1.1.0"),
Copy link
Collaborator

@fassko fassko Sep 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm being picky here, but for consistency let's use same format without .git :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some merge issue, I will update my branch and discards this changes.
I had no intention to change SPM config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's some GH issue, because these files are equal:

https://github.com/daltoniam/Starscream/blob/master/Package.swift
https://github.com/turbulem/Starscream/blob/master/Package.swift

I will make another branch and refresh this PR in order to make it clear.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I can adjust it later myself.

.package(url: "https://github.com/daltoniam/common-crypto-spm", from: "1.1.0")
],
exclude: ["Tests", "examples"]
targets: [
.target(name: "Starscream")
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//////////////////////////////////////////////////////////////////////////////////////////////////

import Foundation
import SSCZLib
import Starscream.SSCZLib

class Decompressor {
private var strm = z_stream()
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import Foundation
import CoreFoundation
import SSCommonCrypto
import Starscream.SSCommonCrypto

public let WebsocketDidConnectNotification = "WebsocketDidConnectNotification"
public let WebsocketDidDisconnectNotification = "WebsocketDidDisconnectNotification"
Expand Down Expand Up @@ -1318,10 +1318,7 @@ open class WebSocket : NSObject, StreamDelegate, WebSocketClient, WSStreamDelega

private extension String {
func sha1Base64() -> String {
let data = self.data(using: String.Encoding.utf8)!
var digest = [UInt8](repeating: 0, count:Int(CC_SHA1_DIGEST_LENGTH))
data.withUnsafeBytes { _ = CC_SHA1($0, CC_LONG(data.count), &digest) }
return Data(bytes: digest).base64EncodedString()
return (self as NSString).ss_SHA1Base64Digest()
}
}

Expand Down
29 changes: 29 additions & 0 deletions Sources/modulemap/CommonCrypto/NSString+SHA1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//////////////////////////////////////////////////////////////////////////////////////////////////
//
// NSString+SHA1.h
// Starscream
//
// Created by Sergey Lem on 6/25/18.
// Copyright (c) 2014-2016 Dalton Cherry.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//////////////////////////////////////////////////////////////////////////////////////////////////

#import <Foundation/Foundation.h>

@interface NSString (SHA1)

- (NSString *)ss_SHA1Base64Digest;

@end
35 changes: 35 additions & 0 deletions Sources/modulemap/CommonCrypto/NSString+SHA1.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//////////////////////////////////////////////////////////////////////////////////////////////////
//
// NSString+SHA1.m
// Starscream
//
// Created by Sergey Lem on 6/25/18.
// Copyright (c) 2014-2016 Dalton Cherry.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//////////////////////////////////////////////////////////////////////////////////////////////////

#import "NSString+SHA1.h"
#import <CommonCrypto/CommonDigest.h>

@implementation NSString (SHA1)

- (NSString *)ss_SHA1Base64Digest {
NSData *stringData = [self dataUsingEncoding:NSUTF8StringEncoding];
NSMutableData *digest = [NSMutableData dataWithLength:CC_SHA1_DIGEST_LENGTH];
CC_SHA1(stringData.bytes, (CC_LONG)stringData.length, digest.mutableBytes);
return [[NSString alloc] initWithData:[digest base64EncodedDataWithOptions:0] encoding:NSUTF8StringEncoding];
}

@end
16 changes: 16 additions & 0 deletions Sources/modulemap/Starscream.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
framework module Starscream {
umbrella header "Starscream.h"

export *

explicit module SSCZLib [system] {
header "include.h"
link "z"
export *
}
explicit module SSCommonCrypto [system] {
private header "NSString+SHA1.h"
link "CommonCrypto"
export *
}
}
1 change: 1 addition & 0 deletions Sources/modulemap/zlib/include.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <zlib.h>
9 changes: 4 additions & 5 deletions Starscream.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ Pod::Spec.new do |s|
s.osx.deployment_target = '10.10'
s.tvos.deployment_target = '9.0'
s.watchos.deployment_target = '2.0'
s.source_files = 'Sources/*.swift'
s.libraries = 'z'
s.source_files = 'Sources/**/*.{h,m,swift}'
s.module_map = 'Sources/modulemap/Starscream.modulemap'
s.private_header_files = 'Sources/modulemap/**/*.h'
s.pod_target_xcconfig = {
'SWIFT_VERSION' => '4.1',
'SWIFT_INCLUDE_PATHS' => '$(PODS_ROOT)/Starscream/zlib'
'SWIFT_VERSION' => '4.1'
}
s.preserve_paths = 'zlib/*'
end
Loading