Skip to content

Commit

Permalink
Add custom wrapper for SHA1 and custom modulemap for framework includ…
Browse files Browse the repository at this point in the history
…ing module maps for CommonCrypto and zlib
  • Loading branch information
turbulem committed Sep 26, 2018
1 parent 94f8d58 commit 70234bc
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Sources/Starscream/Compression.swift
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
7 changes: 2 additions & 5 deletions Sources/Starscream/WebSocket.swift
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, stringData.length, digest.mutableBytes);
return [digest base64EncodedDataWithOptions:0];
}

@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
55 changes: 37 additions & 18 deletions Starscream.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
335FA1FC1F5DF71D00F6D2EC /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = D88EAF811ED4DFD3004FE2C3 /* libz.tbd */; };
33CCF08A1F5DDC030099B092 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = D88EAF811ED4DFD3004FE2C3 /* libz.tbd */; };
33CCF08C1F5DDC030099B092 /* Starscream.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C1360001C473BEF00AA3A01 /* Starscream.h */; settings = {ATTRIBUTES = (Public, ); }; };
33CCF08D1F5DDC030099B092 /* include.h in Headers */ = {isa = PBXBuildFile; fileRef = D85927D71ED76F25003460CB /* include.h */; };
742D12982157CF56006026D7 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 33CCF0921F5DDC030099B092 /* Starscream.framework */; };
DD52B623663980FECD3F6690 /* Compression.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD52B83305DE12CC7F8887D6 /* Compression.swift */; };
DD52B7C033385CD7CF246CC5 /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD52B820CB852287AC065D9C /* WebSocket.swift */; };
DD52BC079AD583D2DA35D7E7 /* SSLClientCertificate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD52B329FF434097A6C8F66E /* SSLClientCertificate.swift */; };
DD52BED25D3DBBB3BC28471B /* SSLSecurity.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD52B3F585852EF29B21F0DB /* SSLSecurity.swift */; };
33CCF08D1F5DDC030099B092 /* include.h in Headers */ = {isa = PBXBuildFile; fileRef = D85927D71ED76F25003460CB /* include.h */; settings = {ATTRIBUTES = (Private, ); }; };
BB8A648020E1105C00527BA5 /* NSString+SHA1.h in Headers */ = {isa = PBXBuildFile; fileRef = BB8A647E20E1105C00527BA5 /* NSString+SHA1.h */; settings = {ATTRIBUTES = (Private, ); }; };
BB8A648120E1105C00527BA5 /* NSString+SHA1.m in Sources */ = {isa = PBXBuildFile; fileRef = BB8A647F20E1105C00527BA5 /* NSString+SHA1.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -27,8 +24,9 @@
5C13600C1C473BFE00AA3A01 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Sources/Info.plist; sourceTree = SOURCE_ROOT; };
6B3E7A0019D48C2F006071F7 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
742419BB1DC6BDBA003ACE43 /* StarscreamTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = StarscreamTests.swift; path = StarscreamTests/StarscreamTests.swift; sourceTree = "<group>"; };
BBC59F4D20D2D71500713D9C /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = "<group>"; };
D85927D61ED761A0003460CB /* module.private.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = module.private.modulemap; sourceTree = "<group>"; };
BB8A647E20E1105C00527BA5 /* NSString+SHA1.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+SHA1.h"; sourceTree = "<group>"; };
BB8A647F20E1105C00527BA5 /* NSString+SHA1.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+SHA1.m"; sourceTree = "<group>"; };
BBC59F4D20D2D71500713D9C /* Starscream.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = Starscream.modulemap; sourceTree = "<group>"; };
D85927D71ED76F25003460CB /* include.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = include.h; sourceTree = "<group>"; };
D88EAF811ED4DFD3004FE2C3 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
D88EAF831ED4E7D8004FE2C3 /* CompressionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompressionTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -58,7 +56,6 @@
6B3E79DC19D48B7F006071F7 = {
isa = PBXGroup;
children = (
D85927D51ED761A0003460CB /* zlib */,
6B3E79E819D48B7F006071F7 /* Sources */,
6B3E79FF19D48C2F006071F7 /* Tests */,
6B3E79E719D48B7F006071F7 /* Products */,
Expand All @@ -78,6 +75,7 @@
6B3E79E819D48B7F006071F7 /* Sources */ = {
isa = PBXGroup;
children = (
BB8A648320E1123400527BA5 /* modulemap */,
5C1360001C473BEF00AA3A01 /* Starscream.h */,
6B3E79E919D48B7F006071F7 /* Supporting Files */,
DD52B820CB852287AC065D9C /* WebSocket.swift */,
Expand Down Expand Up @@ -106,16 +104,33 @@
path = Tests;
sourceTree = "<group>";
};
D85927D51ED761A0003460CB /* zlib */ = {
BB8A647D20E1102900527BA5 /* CommonCrypto */ = {
isa = PBXGroup;
children = (
BB8A647E20E1105C00527BA5 /* NSString+SHA1.h */,
BB8A647F20E1105C00527BA5 /* NSString+SHA1.m */,
);
path = CommonCrypto;
sourceTree = "<group>";
};
BB8A648220E111F200527BA5 /* zlib */ = {
isa = PBXGroup;
children = (
D85927D61ED761A0003460CB /* module.private.modulemap */,
BBC59F4D20D2D71500713D9C /* module.modulemap */,
D85927D71ED76F25003460CB /* include.h */,
);
path = zlib;
sourceTree = "<group>";
};
BB8A648320E1123400527BA5 /* modulemap */ = {
isa = PBXGroup;
children = (
BBC59F4D20D2D71500713D9C /* Starscream.modulemap */,
BB8A647D20E1102900527BA5 /* CommonCrypto */,
BB8A648220E111F200527BA5 /* zlib */,
);
path = modulemap;
sourceTree = "<group>";
};
D88EAF801ED4DFD3004FE2C3 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand All @@ -131,6 +146,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
BB8A648020E1105C00527BA5 /* NSString+SHA1.h in Headers */,
33CCF08C1F5DDC030099B092 /* Starscream.h in Headers */,
33CCF08D1F5DDC030099B092 /* include.h in Headers */,
);
Expand Down Expand Up @@ -188,6 +204,9 @@
335FA1F41F5DF71D00F6D2EC = {
LastSwiftMigration = 0900;
};
33CCF0841F5DDC030099B092 = {
LastSwiftMigration = 0940;
};
};
};
buildConfigurationList = 6B3E79E019D48B7F006071F7 /* Build configuration list for PBXProject "Starscream" */;
Expand Down Expand Up @@ -239,10 +258,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DD52B7C033385CD7CF246CC5 /* WebSocket.swift in Sources */,
DD52BC079AD583D2DA35D7E7 /* SSLClientCertificate.swift in Sources */,
DD52BED25D3DBBB3BC28471B /* SSLSecurity.swift in Sources */,
DD52B623663980FECD3F6690 /* Compression.swift in Sources */,
33CCF0861F5DDC030099B092 /* Compression.swift in Sources */,
33CCF0871F5DDC030099B092 /* WebSocket.swift in Sources */,
BB8A648120E1105C00527BA5 /* NSString+SHA1.m in Sources */,
33CCF0881F5DDC030099B092 /* SSLSecurity.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -316,6 +335,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MODULEMAP_FILE = $SRCROOT/Sources/modulemap/Starscream.modulemap;
OTHER_LDFLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = "com.vluxe.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -349,6 +369,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
MODULEMAP_FILE = $SRCROOT/Sources/modulemap/Starscream.modulemap;
OTHER_LDFLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = "com.vluxe.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -416,7 +437,6 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = "";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx appletvos appletvsimulator watchsimulator watchos";
SWIFT_INCLUDE_PATHS = $SRCROOT/zlib;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
Expand Down Expand Up @@ -469,7 +489,6 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = "";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx appletvos appletvsimulator watchsimulator watchos";
SWIFT_INCLUDE_PATHS = $SRCROOT/zlib;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
VALIDATE_PRODUCT = YES;
Expand Down
2 changes: 0 additions & 2 deletions zlib/include.h

This file was deleted.

1 change: 0 additions & 1 deletion zlib/module.modulemap

This file was deleted.

9 changes: 0 additions & 9 deletions zlib/module.private.modulemap

This file was deleted.

0 comments on commit 70234bc

Please sign in to comment.