Commit a60b036d authored by Drew's avatar Drew

Add genericHash for arrays

parent d5af0cb3
Pipeline #571 passed with stages
......@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
This project does not follow semver.
# Unreleased
* Add genericHash for arrays
# 1.0.6.1 - 2015-12-07
* Adding PublicKey.humanReadable and corresponding constructor
......
......@@ -83,6 +83,8 @@
3A8ED35C1BB27E6E00164375 /* Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8ED35B1BB27E6E00164375 /* Random.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 */; };
3AAC8C7F1C1CFEF500B82F4D /* GenericHashTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AAC8C7E1C1CFEF500B82F4D /* GenericHashTests.swift */; };
3AC7C1BF1BC157A20036FABB /* memcmp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC7C1BE1BC157A20036FABB /* memcmp.swift */; };
3AC7C1C11BC1594D0036FABB /* MemCmpTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC7C1C01BC1594D0036FABB /* MemCmpTests.swift */; };
3AD35A341C14E3FB0095BFB4 /* PublicKey+Human.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AD35A331C14E3FB0095BFB4 /* PublicKey+Human.swift */; };
......@@ -178,6 +180,8 @@
3AAAC7AF1B80AB40009431FC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3AAAC7B41B80AB40009431FC /* NaOHTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NaOHTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3AAAC7BB1B80AB40009431FC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3AAC8C7C1C1CFEEA00B82F4D /* GenericHash.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GenericHash.swift; sourceTree = "<group>"; };
3AAC8C7E1C1CFEF500B82F4D /* GenericHashTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GenericHashTests.swift; sourceTree = "<group>"; };
3AC7C1BE1BC157A20036FABB /* memcmp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = memcmp.swift; sourceTree = "<group>"; };
3AC7C1C01BC1594D0036FABB /* MemCmpTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MemCmpTests.swift; sourceTree = "<group>"; };
3AD35A331C14E3FB0095BFB4 /* PublicKey+Human.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "PublicKey+Human.swift"; sourceTree = "<group>"; };
......@@ -240,6 +244,7 @@
3A8ED35B1BB27E6E00164375 /* Random.swift */,
3AC7C1BE1BC157A20036FABB /* memcmp.swift */,
3AD35A331C14E3FB0095BFB4 /* PublicKey+Human.swift */,
3AAC8C7C1C1CFEEA00B82F4D /* GenericHash.swift */,
);
path = NaOH;
sourceTree = "<group>";
......@@ -256,6 +261,7 @@
3A1922091B8112170092C6B1 /* CryptoBoxTests.swift */,
3A2AF84D1B95B52500A3BEF3 /* CryptoStreamTests.swift */,
3AC7C1C01BC1594D0036FABB /* MemCmpTests.swift */,
3AAC8C7E1C1CFEF500B82F4D /* GenericHashTests.swift */,
);
path = NaOHTests;
sourceTree = "<group>";
......@@ -515,6 +521,7 @@
buildActionMask = 2147483647;
files = (
3A2AF84C1B95B3A400A3BEF3 /* crypto_stream_chacha20.swift in Sources */,
3AAC8C7D1C1CFEEA00B82F4D /* GenericHash.swift in Sources */,
3A1922131B811DD50092C6B1 /* Key+Zeroing.swift in Sources */,
3A8ED35C1BB27E6E00164375 /* Random.swift in Sources */,
3A1922061B810D390092C6B1 /* PublicKey.swift in Sources */,
......@@ -534,6 +541,7 @@
buildActionMask = 2147483647;
files = (
3AC7C1C11BC1594D0036FABB /* MemCmpTests.swift in Sources */,
3AAC8C7F1C1CFEF500B82F4D /* GenericHashTests.swift in Sources */,
3A19220A1B8112170092C6B1 /* CryptoBoxTests.swift in Sources */,
3A526FE01B80AD4F0092BA60 /* KeyTests.swift in Sources */,
3A2AF84E1B95B52500A3BEF3 /* CryptoStreamTests.swift in Sources */,
......
//
// GenericHash.swift
// NaOH
//
// Created by Drew Crawford on 12/12/15.
// Copyright © 2015 DrewCrawfordApps. All rights reserved.
//
import Foundation
extension Array {
var genericHash: [UInt8] {
get {
precondition(Element.self == UInt8.self, "genericHash is only implemented for type UInt8, not \(Element.self)") //I'm not sure this works for other arrays
//sadly, we can't extend a particular one until Swift 3
var out = [UInt8](count: Int(crypto_generichash_BYTES), repeatedValue: 0)
self.withUnsafeBufferPointer { (ptr) -> () in
let cast : UnsafePointer<UInt8> = UnsafePointer(ptr.baseAddress)
crypto_generichash(&out, out.count, cast, UInt64(ptr.count), nil, 0)
}
return out
}
}
}
\ No newline at end of file
//
// GenericHashTests.swift
// NaOH
//
// Created by Drew Crawford on 12/12/15.
// Copyright © 2015 DrewCrawfordApps. All rights reserved.
// 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
import XCTest
@testable import NaOH
class GenericHashTests : XCTestCase {
func testGenericHash() {
let a: [UInt8] = [0,1,2]
let hash1 = a.genericHash
let hash2 = a.genericHash
XCTAssert(hash1 == hash2)
XCTAssert(hash1 != ([0,1,3] as [UInt8]).genericHash)
XCTAssert(hash1 != ([0,1,2,3] as [UInt8]).genericHash)
}
}
\ No newline at end of file
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