Commit 2986a353 authored by Drew's avatar Drew

Linux port and making tests pass under atbuild-0.5.0-dev on osx

parent a816dbb7
[submodule "AnarchyDispatch"]
path = AnarchyDispatch
url = git@github.com:AnarchyTools/AnarchyDispatch.git
Subproject commit d59340045fe4a647fdc1dc91fc0ca17d69018b4d
......@@ -100,6 +100,7 @@
3A98E1281C23A2A800B267A0 /* NaOH.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AF839C11C22BAE6003EDAC1 /* NaOH.framework */; };
3A98E1291C23A2A800B267A0 /* NaOH.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3AF839C11C22BAE6003EDAC1 /* NaOH.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3A98E1F31C240F2800B267A0 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 3A526FE21B80B4E90092BA60 /* LICENSE */; };
3AA296441C4D4BC200163C2D /* ICantBelieveItsNotFoundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA296431C4D4BC200163C2D /* ICantBelieveItsNotFoundation.swift */; };
3AAAC7AE1B80AB40009431FC /* NaOH.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AAAC7AD1B80AB40009431FC /* NaOH.h */; settings = {ATTRIBUTES = (Public, ); }; };
3AAAC7B51B80AB40009431FC /* NaOH.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AAAC7AA1B80AB40009431FC /* NaOH.framework */; };
3AAC8C7D1C1CFEEA00B82F4D /* GenericHash.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AAC8C7C1C1CFEEA00B82F4D /* GenericHash.swift */; };
......@@ -306,6 +307,7 @@
3A526FE21B80B4E90092BA60 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
3A6C74E01C0842700055B55B /* crypto_aead_aes256gcm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crypto_aead_aes256gcm.h; sourceTree = "<group>"; };
3A8ED35B1BB27E6E00164375 /* Random.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Random.swift; sourceTree = "<group>"; };
3AA296431C4D4BC200163C2D /* ICantBelieveItsNotFoundation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ICantBelieveItsNotFoundation.swift; sourceTree = "<group>"; };
3AAAC7AA1B80AB40009431FC /* NaOH.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = NaOH.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3AAAC7AD1B80AB40009431FC /* NaOH.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NaOH.h; sourceTree = "<group>"; };
3AAAC7AF1B80AB40009431FC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
......@@ -489,6 +491,7 @@
3AAC8C7C1C1CFEEA00B82F4D /* GenericHash.swift */,
3AB474D41C1D988800651809 /* increment.swift */,
3AB474D81C1D9A1D00651809 /* Integer192Bit.swift */,
3AA296431C4D4BC200163C2D /* ICantBelieveItsNotFoundation.swift */,
);
path = NaOH;
sourceTree = "<group>";
......@@ -1030,6 +1033,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3AA296441C4D4BC200163C2D /* ICantBelieveItsNotFoundation.swift in Sources */,
3A2AF84C1B95B3A400A3BEF3 /* crypto_stream_chacha20.swift in Sources */,
3AB474D51C1D988800651809 /* increment.swift in Sources */,
3AAC8C7D1C1CFEEA00B82F4D /* GenericHash.swift in Sources */,
......
// This file is part of NaOH. It is subject to the license terms in the LICENSE
// file found in the top level of this distribution
// No part of NaOH, including this file, may be copied, modified,
// propagated, or distributed except according to the terms contained
// in the LICENSE file.
import Foundation
//SR-138
#if os(Linux)
extension String {
@warn_unused_result
public func cStringUsingEncoding(encoding: NSStringEncoding) -> [CChar]? {
let strNS = self.bridge()
let bytes = strNS.cStringUsingEncoding(NSUTF8StringEncoding)
let bfrPointer = UnsafeBufferPointer(start: bytes, count: strNS.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
var arr = [CChar](bfrPointer)
strNS.description //don't optimize out
return arr
}
}
#endif
......@@ -14,6 +14,9 @@ import Foundation
#if ATBUILD
import CSodium
#endif
#if os(Linux)
import Glibc //⛏567
#endif
extension Key {
/**Saves the key to the file indicated.
......@@ -42,7 +45,8 @@ extension Key {
public convenience init (readFromFile file: String) throws {
//check attributes
let attributes = try NSFileManager.defaultManager().attributesOfItemAtPath(file)
if attributes[NSFilePosixPermissions]?.shortValue != 0o0600 {
guard let num = attributes[NSFilePosixPermissions] as? NSNumber else { fatalError("Weird; why isn't \(attributes[NSFilePosixPermissions]) an NSNumber?") }
if num.shortValue != 0o0600 {
throw NaOHError.FilePermissionsLookSuspicious
}
let mutableData = try NSMutableData(contentsOfFile: file, options: NSDataReadingOptions())
......
......@@ -12,6 +12,9 @@
#if ATBUILD
import CSodium
#endif
#if os(Linux)
import Glibc //⛏567
#endif
import Foundation
extension Key {
......
......@@ -64,7 +64,7 @@ public final class Key {
}
var str = ""
for char in hash {
str += NSString(format: "%02X", char) as String
str += String(format: "%02X", arguments: [char]) as String
}
return str
}
......
......@@ -13,6 +13,7 @@
import Foundation
#if ATBUILD
import CSodium
import AnarchyDispatch
#endif
func sodium_init_wrap() {
......@@ -30,7 +31,7 @@ func sodium_init_wrap() {
func debugValue(var value: UnsafePointer<UInt8>, size: Int) -> String {
var str = ""
for i in 0..<size {
str += NSString(format: "%02X", value.memory) as String
str += String(format: "%02X", arguments: [value.memory]) as String
if i != size - 1 { value = value.successor() }
}
return str
......
......@@ -22,8 +22,13 @@ class CryptoBoxTests :XCTestCase {
private let knownCiphertext : [UInt8] = [211, 170, 214, 228, 186, 238, 171, 198, 216, 148, 136, 65, 140, 6, 22, 100, 5, 32, 23]
func aliceBob() -> (PublicKey, PublicKey) {
#if ATBUILD
let alicePath = "NaOHTests/alice.key"
let bobPath = "NaOHTests/bob.key"
#else
let alicePath = NSBundle(forClass: CryptoBoxTests.self).pathForResource("alice", ofType: "key")!
let bobPath = NSBundle(forClass: CryptoBoxTests.self).pathForResource("bob", ofType: "key")!
#endif
//fix the permsisions on this key so we don't freak out the security goalie
try! NSFileManager.defaultManager().setAttributes([NSFilePosixPermissions: NSNumber(short: 0o0600)], ofItemAtPath: alicePath)
......@@ -46,5 +51,14 @@ class CryptoBoxTests :XCTestCase {
let plain = try! crypto_box_open(knownCiphertext, to: alice.secretKey!, from: bob, nonce: notVeryNonce)
XCTAssert(plain == knownPlaintext)
}
}
\ No newline at end of file
}
#if ATBUILD
extension CryptoBoxTests : XCTestCaseProvider {
var allTests : [(String, () -> Void)] {
return [
("testCryptoBox", testCryptoBox),
("testCryptoBoxOpen", testCryptoBoxOpen)
]
}
}
#endif
\ No newline at end of file
......@@ -42,4 +42,12 @@ class CryptoSecretBoxTests : XCTestCase {
}
import Foundation
extension CryptoSecretBoxTests : XCTestCaseProvider {
var allTests : [(String, () -> Void)] {
return [
("testEncrypt", testEncrypt),
("testDecrypt", testDecrypt),
("testBadDecrypt", testBadDecrypt)
]
}
}
......@@ -23,4 +23,11 @@ class CryptoStreamTestsTests : XCTestCase {
let plaintext = crypto_stream_chacha20_xor(ciphertext, nonce: nonce, key: key)
XCTAssert(plaintext == [1,2,3])
}
}
extension CryptoStreamTestsTests : XCTestCaseProvider {
var allTests : [(String, () -> Void)] {
return [
("testChaCha20", testChaCha20)
]
}
}
\ No newline at end of file
......@@ -26,4 +26,12 @@ class GenericHashTests : XCTestCase {
XCTAssert(hash1 != ([0,1,2,3] as [UInt8]).genericHash)
}
}
extension GenericHashTests : XCTestCaseProvider {
var allTests : [(String, () -> Void)] {
return [
("testGenericHash", testGenericHash)
]
}
}
\ No newline at end of file
......@@ -33,4 +33,13 @@ class IncrementTestsTests : XCTestCase {
XCTAssert(i.byteRepresentation == [0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
}
}
\ No newline at end of file
}
#if ATBUILD
extension IncrementTestsTests : XCTestCaseProvider {
var allTests : [(String, () -> Void)] {
return [
("testInteger192Bit", testInteger192Bit)
]
}
}
#endif
\ No newline at end of file
......@@ -33,4 +33,13 @@ class KeyFileTests : XCTestCase {
XCTAssert(pk.bytes == pk2.bytes)
}
}
extension KeyFileTests : XCTestCaseProvider {
var allTests : [(String, () -> Void)] {
return [
("testKeyLoadSave", testKeyLoadSave),
("testPublicKeyLoadSave",testPublicKeyLoadSave)
]
}
}
\ No newline at end of file
......@@ -58,4 +58,18 @@ class KeyTests : XCTestCase {
XCTAssert(a == b)
}
}
#if ATBUILD
extension KeyTests : XCTestCaseProvider {
var allTests : [(String, () -> Void)] {
return [
("testKey", testKey),
("testZeroImport", testZeroImport),
("testCrypto", testCrypto),
("testOverwriteKey",testOverwriteKey),
("testCryptoBoxKey",testCryptoBoxKey),
("testHumanReadable",testHumanReadable)
]
}
}
#endif
......@@ -18,4 +18,12 @@ class MemCmpTests : XCTestCase {
XCTAssert(sodium_memcmp([1,2,3], [1,2,3]))
XCTAssert(!sodium_memcmp([1,2,3], [1,3,3]))
}
}
\ No newline at end of file
}
#if ATBUILD
extension MemCmpTests : XCTestCaseProvider {
var allTests : [(String, () -> Void)] {
return [
("testMemCmp", testMemCmp)]
}
}
#endif
\ No newline at end of file
(package
:name "NaOH"
:import ["AnarchyDispatch/build.atpkg"]
:tasks {
:libsodium {
:tool "shell"
:script "./libsodium/build.sh"
}
:default {
:NaOH {
:tool "atllbuild"
:source ["NaOH/**.swift"]
:name "NaOH"
:outputType "static-library"
:dependencies ["libsodium"]
:dependencies ["libsodium" "AnarchyDispatch.default"]
:compileOptions ["-I" "libsodium/" "-enable-testing"]
:overlays {
:osx {
:overlay ["AnarchyDispatch.compile-osx"]
}
:linux {
:overlay ["AnarchyDispatch.compile-linux"]
}
}
}
:build-tests {
......@@ -20,10 +32,26 @@
:source ["NaOHTests/**.swift"]
:name "NaOHTests"
:outputType "executable"
:dependencies ["default"]
:compileOptions ["-F" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/" "-I" "libsodium/"]
:linkOptions ["-F" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/" "-L" "libsodium/libsodium/src/libsodium/.libs/" "-lsodium" "-target" "x86_64-apple-macosx10.11" "-Xlinker" "-rpath" "-Xlinker" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/" "-Xlinker" "-bundle"]
:dependencies ["NaOH"]
:xctestify true
:xctestStrict true
:compileOptions ["-I" "libsodium/"]
:linkOptions ["-Xlinker" "libsodium/libsodium/src/libsodium/.libs/libsodium.a"]
:linkWithProduct ["NaOH.a"]
:overlays {
:osx {
:overlay ["AnarchyDispatch.compile-osx"]
}
:linux {
:overlay ["AnarchyDispatch.compile-linux"]
}
}
}
:run-tests {
:tool "xctestrun"
:testExecutable ".atllbuild/products/NaOHTests"
:dependencies ["build-tests"]
}
}
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment