TRAVIS_OS_NAME=osx TRAVIS_RUBY_VERSION=default <<<<<< ENV .swift-version Example/Podfile Example/Podfile.lock Example/Podfile~ Example/Pods/Local Podspecs/RLPSwift.podspec.json Example/Pods/Manifest.lock Example/Pods/Pods.xcodeproj/project.pbxproj Example/Pods/Target Support Files/Pods-RLPSwiftExample/Info.plist Example/Pods/Target Support Files/Pods-RLPSwiftExample/Pods-RLPSwiftExample-acknowledgements.markdown Example/Pods/Target Support Files/Pods-RLPSwiftExample/Pods-RLPSwiftExample-acknowledgements.plist Example/Pods/Target Support Files/Pods-RLPSwiftExample/Pods-RLPSwiftExample-dummy.m Example/Pods/Target Support Files/Pods-RLPSwiftExample/Pods-RLPSwiftExample-frameworks.sh Example/Pods/Target Support Files/Pods-RLPSwiftExample/Pods-RLPSwiftExample-resources.sh Example/Pods/Target Support Files/Pods-RLPSwiftExample/Pods-RLPSwiftExample-umbrella.h Example/Pods/Target Support Files/Pods-RLPSwiftExample/Pods-RLPSwiftExample.debug.xcconfig Example/Pods/Target Support Files/Pods-RLPSwiftExample/Pods-RLPSwiftExample.modulemap Example/Pods/Target Support Files/Pods-RLPSwiftExample/Pods-RLPSwiftExample.release.xcconfig Example/Pods/Target Support Files/RLPSwift/Info.plist Example/Pods/Target Support Files/RLPSwift/RLPSwift-dummy.m Example/Pods/Target Support Files/RLPSwift/RLPSwift-prefix.pch Example/Pods/Target Support Files/RLPSwift/RLPSwift-umbrella.h Example/Pods/Target Support Files/RLPSwift/RLPSwift.modulemap Example/Pods/Target Support Files/RLPSwift/RLPSwift.xcconfig Example/RLPSwiftExample.xcodeproj/project.pbxproj Example/RLPSwiftExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata Example/RLPSwiftExample.xcworkspace/contents.xcworkspacedata Example/RLPSwiftExample/AppDelegate.swift Example/RLPSwiftExample/Assets.xcassets/AppIcon.appiconset/Contents.json Example/RLPSwiftExample/Base.lproj/LaunchScreen.storyboard Example/RLPSwiftExample/Base.lproj/Main.storyboard Example/RLPSwiftExample/Info.plist Example/RLPSwiftExample/ViewController.swift LICENSE Package.swift RLPSwift.podspec RLPSwift.xcodeproj/project.pbxproj RLPSwift.xcodeproj/xcshareddata/xcschemes/RLPSwift.xcscheme RLPSwift.xcodeproj/xcshareddata/xcschemes/RLPSwiftTests.xcscheme Source/Info.plist Source/RLP.swift Source/RLPSwift.h Source/UInt32+byteArrayLittleEndian.swift Tests/Info.plist Tests/RLPTests.swift Tests/UInt32ExtensionsTests.swift fastlane/Scanfile <<<<<< network # path=RLPSwift.framework.coverage.txt /Users/travis/build/bitfwdcommunity/RLPSwift/Source/RLP.swift: 1| |// Created by Aleph Retamal on 31/1/18. 2| |// Copyright © 2018 Lalacode. All rights reserved. 3| | 4| |import Foundation 5| | 6| |public enum RLP { 7| | public enum Error: Swift.Error { 8| | case stringToData 9| | case dataToString 10| | case invalidObject(ofType: Any.Type, expected: Any.Type) 11| | 12| 0| public var localizedDescription: String { 13| 0| switch self { 14| 0| case .stringToData: return "Failed to convert String to Data" 15| 0| case .dataToString: return "Failed to convert Data to String" 16| 0| case .invalidObject(let got, let expected): 17| 0| return "Invalid object, expected \(expected), but got \(got)" 18| 0| } 19| 0| } 20| | } 21| |} 22| | 23| |// MARK: Internal helpers 24| |internal extension RLP { 25| 7| static func binaryLength(of n: UInt32) -> UInt8 { 26| 7| return UInt8(ceil(log10(Double(n))/log10(Double(UInt8.max)))) 27| 7| } 28| | 29| 22| static func encodeLength(_ length: UInt32, offset: UInt8) -> Data { 30| 18| if length < 56 { 31| 18| let lengthByte = offset + UInt8(length) 32| 18| return Data(bytes: [lengthByte]) 33| 4| } else { 34| 4| let firstByte = offset + 55 + binaryLength(of: length) 35| 4| var bytes = [firstByte] 36| 4| bytes.append(contentsOf: length.byteArrayLittleEndian) 37| 4| return Data(bytes: bytes) 38| 0| } 39| 0| } 40| |} 41| | 42| |// MARK: Data encoding 43| |public extension RLP { 44| 15| public static func encode(_ data: Data) -> Data { 45| 15| if data.count == 1, 46| 6| 0x00...0x7f ~= data[0] { 47| 6| return data 48| 9| } else { 49| 9| var result = encodeLength(UInt32(data.count), offset: 0x80) 50| 9| result.append(contentsOf: data) 51| 9| return result 52| 0| } 53| 0| } 54| | 55| 8| public static func encode(nestedArrayOfData array: [Any]) throws -> Data { 56| 8| var output = Data() 57| 8| 58| 7| for item in array { 59| 0| if let data = item as? Data { 60| 0| output.append(encode(data)) 61| 7| } else if let array = item as? [Any] { 62| 7| output.append(try encode(nestedArrayOfData: array)) 63| 7| } else { 64| 0| throw Error.invalidObject(ofType: Mirror(reflecting: item).subjectType, expected: Data.self) 65| 7| } 66| 8| } 67| 8| let encodedLength = encodeLength(UInt32(output.count), offset: 0xc0) 68| 8| output.insert(contentsOf: encodedLength, at: 0) 69| 8| return output 70| 8| } 71| |} 72| | 73| |// MARK: String encoding 74| |public extension RLP { 75| 8| public static func encode(_ string: String, with encoding: String.Encoding = .ascii) throws -> Data { 76| 0| guard let data = string.data(using: encoding) else { 77| 0| throw Error.stringToData 78| 8| } 79| 8| 80| 8| let bytes = encode(data) 81| 8| 82| 8| return bytes 83| 8| } 84| | 85| 0| public static func encode(nestedArrayOfString array: [Any], encodeStringsWith encoding: String.Encoding = .ascii) throws -> Data { 86| 0| var output = Data() 87| 0| 88| 0| for item in array { 89| 0| if let string = item as? String { 90| 0| output.append(try encode(string, with: .ascii)) 91| 0| } else if let array = item as? [Any] { 92| 0| output.append(try encode(nestedArrayOfString: array, encodeStringsWith: encoding)) 93| 0| } else { 94| 0| throw Error.invalidObject(ofType: Mirror(reflecting: item).subjectType, expected: String.self) 95| 0| } 96| 0| } 97| 0| 98| 0| return output 99| 0| } 100| |} /Users/travis/build/bitfwdcommunity/RLPSwift/Source/UInt32+byteArrayLittleEndian.swift: 1| |// Created by Aleph Retamal on 2/2/18. 2| |// Copyright © 2018 Lalacode. All rights reserved. 3| | 4| |extension UInt32 { 5| 5| var byteArrayLittleEndian: [UInt8] { 6| 5| return [ 7| 5| UInt8((self & 0xFF000000) >> 24), 8| 5| UInt8((self & 0x00FF0000) >> 16), 9| 5| UInt8((self & 0x0000FF00) >> 8), 10| 5| UInt8(self & 0x000000FF) 11| 5| ] 12| 5| } 13| |} <<<<<< EOF # path=RLPSwiftTests.xctest.coverage.txt /Users/travis/build/bitfwdcommunity/RLPSwift/Tests/RLPTests.swift: 1| |// Created by Aleph Retamal on 31/1/18. 2| |// Copyright © 2018 Lalacode. All rights reserved. 3| | 4| |import XCTest 5| |@testable 6| |import RLPSwift 7| | 8| |class RLPTests: XCTestCase { } 9| | 10| |// MARK: Helpers tests 11| |extension RLPTests { 12| 1| func testBinaryLength() { 13| 1| XCTAssertEqual(RLP.binaryLength(of: 0xff), 1) 14| 1| XCTAssertEqual(RLP.binaryLength(of: 0xfff), 2) 15| 1| XCTAssertEqual(RLP.binaryLength(of: 0xffff), 3) 16| 1| } 17| | 18| 1| func testEncodeLengthSmallerThanOrEqualTo55() { 19| 1| XCTAssertEqual(RLP.encodeLength(0x00, offset: 0x80), Data(bytes: [0x80])) 20| 1| XCTAssertEqual(RLP.encodeLength(0x37, offset: 0x80), Data(bytes: [0xb7])) 21| 1| } 22| | 23| 1| func testEncodeLengthGreaterThan55() { 24| 1| XCTAssertEqual(RLP.encodeLength(0x38, offset: 0x80), Data(bytes: [0xb8, 0x0, 0x0, 0x0, 0x38])) 25| 1| XCTAssertEqual(RLP.encodeLength(0x0400, offset: 0x80), Data(bytes: [0xb9, 0x0, 0x0, 0x04, 0x0])) 26| 1| XCTAssertEqual(RLP.encodeLength(0x11170, offset: 0x80), Data(bytes: [0xba, 0x0, 0x01, 0x11, 0x70])) 27| 1| } 28| |} 29| | 30| | 31| |// MARK: Data encoding tests 32| |extension RLPTests { 33| 1| func testEncodeEmptyData() { 34| 1| let subject = Data() 35| 1| XCTAssertEqual(RLP.encode(subject), Data(bytes: [0x80])) 36| 1| } 37| | 38| 1| func testEncodeDataWithSingleByte() { 39| 1| XCTAssertEqual(RLP.encode(Data(bytes: [0x30])), Data(bytes: [0x30])) 40| 1| XCTAssertEqual(RLP.encode(Data(bytes: [0x61])), Data(bytes: [0x61])) 41| 1| XCTAssertEqual(RLP.encode(Data(bytes: [0x7b])), Data(bytes: [0x7b])) 42| 1| } 43| | 44| 1| func testEncodeDataSmallerThan55Bytes() { 45| 1| XCTAssertEqual(RLP.encode(Data(bytes: [0x31, 0x30, 0x30])), Data(bytes: [0x83, 0x31, 0x30, 0x30])) 46| 1| XCTAssertEqual(RLP.encode(Data(bytes: [0x4c, 0x6f, 0x72, 0x65, 0x6d, 0x20, 0x69, 0x70, 0x73, 0x75, 0x6d, 0x20, 0x64, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x73, 0x69, 0x74, 0x20, 0x61, 0x6d, 0x65, 0x74])), Data(bytes: [0x9a, 0x4c, 0x6f, 0x72, 0x65, 0x6d, 0x20, 0x69, 0x70, 0x73, 0x75, 0x6d, 0x20, 0x64, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x73, 0x69, 0x74, 0x20, 0x61, 0x6d, 0x65, 0x74])) 47| 1| } 48| | 49| 1| func testEncodeDataEqualTo55Bytes() { 50| 1| let subject = Data(bytes: [UInt8](repeating: 0x61, count: 55)) 51| 1| let expectedBytes = [0xb7] + subject 52| 1| XCTAssertEqual(RLP.encode(subject), Data(bytes: expectedBytes)) 53| 1| } 54| | 55| 1| func testEncodeTheoreticalRepresentationOfTwo() { 56| 1| let subject: [Any] = [ [], [[]], [ [], [[]] ] ] 57| 1| 58| 1| XCTAssertEqual(try RLP.encode(nestedArrayOfData: subject), Data(bytes: [0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0])) 59| 1| } 60| |} 61| | 62| |// MARK: String encoding tests 63| |extension RLPTests { 64| | 65| 1| func testEncodeEmptyString() { 66| 1| XCTAssertEqual(try? RLP.encode(""), Data(bytes: [0x80])) 67| 1| } 68| | 69| 1| func testEncodeStringWithSingleByte() { 70| 1| XCTAssertEqual(try? RLP.encode("0"), Data(bytes: [0x30])) 71| 1| XCTAssertEqual(try? RLP.encode("a"), Data(bytes: [0x61])) 72| 1| XCTAssertEqual(try? RLP.encode("{"), Data(bytes: [0x7b])) 73| 1| } 74| | 75| 1| func testEncodeStringSmallerThan55Bytes() { 76| 1| XCTAssertEqual(try? RLP.encode("100"), Data(bytes: [0x83, 0x31, 0x30, 0x30])) 77| 1| XCTAssertEqual(try? RLP.encode("Lorem ipsum dolor sit amet"), Data(bytes: [0x9a, 0x4c, 0x6f, 0x72, 0x65, 0x6d, 0x20, 0x69, 0x70, 0x73, 0x75, 0x6d, 0x20, 0x64, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x73, 0x69, 0x74, 0x20, 0x61, 0x6d, 0x65, 0x74])) 78| 1| } 79| | 80| 1| func testEncodeStringEqualTo55Bytes() { 81| 1| let subject = [String](repeating: "a", count: 55).reduce("", +) 82| 1| let expectedBytes: [UInt8] = [0xb7] + [UInt8](repeating: 0x61, count: 55) 83| 1| XCTAssertEqual(try? RLP.encode(subject), Data(bytes: expectedBytes)) 84| 1| } 85| | 86| 1| func testEncodeStringGreaterThan55Bytes() { 87| 1| let stringWith400a = [String](repeating: "a", count: 400).reduce("", +) 88| 1| let expectedBytes: [UInt8] = [0xb9, 0x00, 0x00, 0x01, 0x90] + [UInt8](repeating: 0x61, count: 400) 89| 1| XCTAssertEqual(try? RLP.encode(stringWith400a), Data(bytes: expectedBytes)) 90| 1| } 91| |} /Users/travis/build/bitfwdcommunity/RLPSwift/Tests/UInt32ExtensionsTests.swift: 1| |// Created by Aleph Retamal on 31/1/18. 2| |// Copyright © 2018 Lalacode. All rights reserved. 3| | 4| |import XCTest 5| |@testable 6| |import RLPSwift 7| | 8| |class UInt32ExtensionsTests: XCTestCase { 9| 1| func testByteArrayLittleEndian() { 10| 1| let subject: UInt32 = 0x12345 11| 1| let expected: [UInt8] = [0x00, 0x01, 0x23, 0x45] 12| 1| 13| 1| XCTAssertEqual(subject.byteArrayLittleEndian, expected) 14| 1| } 15| |} <<<<<< EOF # path=fixes ./Example/Pods/Target Support Files/Pods-RLPSwiftExample/Pods-RLPSwiftExample-umbrella.h:12,13,16 ./Example/Pods/Target Support Files/RLPSwift/RLPSwift-umbrella.h:12,14,17 ./Source/RLPSwift.h:3,5,8 <<<<<< EOF