Skip to content

Commit

Permalink
Merge pull request #21 from tayloraswift/uuid
Browse files Browse the repository at this point in the history
UUID
  • Loading branch information
tayloraswift authored Nov 18, 2024
2 parents e604843 + 40421db commit 5550cee
Show file tree
Hide file tree
Showing 21 changed files with 714 additions and 639 deletions.
23 changes: 0 additions & 23 deletions Package.resolved

This file was deleted.

45 changes: 19 additions & 26 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
// swift-tools-version:5.8
// swift-tools-version:6.0
import PackageDescription

let package:Package = .init(
name: "swift-hash",
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)],
platforms: [.macOS(.v14), .iOS(.v17), .tvOS(.v17), .visionOS(.v1), .watchOS(.v10)],
products: [
.library(name: "Base16", targets: ["Base16"]),
.library(name: "Base64", targets: ["Base64"]),
.library(name: "CRC", targets: ["CRC"]),
.library(name: "InlineBuffer", targets: ["InlineBuffer"]),
.library(name: "MD5", targets: ["MD5"]),
.library(name: "Base16", targets: ["Base16"]),
.library(name: "Base64", targets: ["Base64"]),
.library(name: "CRC", targets: ["CRC"]),
.library(name: "InlineBuffer", targets: ["InlineBuffer"]),
.library(name: "MD5", targets: ["MD5"]),
.library(name: "MessageAuthentication", targets: ["MessageAuthentication"]),
.library(name: "SHA1", targets: ["SHA1"]),
.library(name: "SHA2", targets: ["SHA2"]),
],
dependencies: [
.package(url: "https://github.com/tayloraswift/swift-grammar", .upToNextMinor(
from: "0.4.0")),
.library(name: "SHA1", targets: ["SHA1"]),
.library(name: "SHA2", targets: ["SHA2"]),
.library(name: "UUID", targets: ["UUID"]),
],
targets: [
.target(name: "BaseDigits"),
Expand Down Expand Up @@ -56,27 +53,28 @@ let package:Package = .init(
.target(name: "MessageAuthentication"),
]),

.executableTarget(name: "Base64Tests",
.target(name: "UUID",
dependencies: [
.target(name: "Base16"),
]),

.testTarget(name: "Base64Tests",
dependencies: [
.product(name: "Testing_", package: "swift-grammar"),
.target(name: "Base64"),
]),

.executableTarget(name: "CRCTests",
.testTarget(name: "CRCTests",
dependencies: [
.product(name: "Testing_", package: "swift-grammar"),
.target(name: "CRC"),
]),

.executableTarget(name: "MD5Tests",
.testTarget(name: "MD5Tests",
dependencies: [
.target(name: "MD5"),
.product(name: "Testing_", package: "swift-grammar"),
]),

.executableTarget(name: "SHA2Tests",
.testTarget(name: "SHA2Tests",
dependencies: [
.product(name: "Testing_", package: "swift-grammar"),
.target(name: "SHA2"),
]),
]
Expand All @@ -87,12 +85,7 @@ for target:PackageDescription.Target in package.targets
{
var settings:[PackageDescription.SwiftSetting] = $0 ?? []

settings.append(.enableUpcomingFeature("BareSlashRegexLiterals"))
settings.append(.enableUpcomingFeature("ConciseMagicFile"))
settings.append(.enableUpcomingFeature("DeprecateApplicationMain"))
settings.append(.enableUpcomingFeature("ExistentialAny"))
settings.append(.enableUpcomingFeature("GlobalConcurrency"))
settings.append(.enableUpcomingFeature("IsolatedDefaultValues"))
settings.append(.enableExperimentalFeature("StrictConcurrency"))

settings.append(.define("DEBUG", .when(configuration: .debug)))
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

## Requirements

The swift-hash library requires Swift 5.9 or later.
The swift-hash library requires Swift 6.0 or later.


| Platform | Status |
Expand Down Expand Up @@ -65,3 +65,7 @@ This package vends the following library products:
1. [`SHA2`](https://swiftinit.org/docs/swift-hash/sha2)

Implements the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) hashing function.

1. [`UUID`](https://swiftinit.org/docs/swift-hash/uuid)

Provides a UUID type.
7 changes: 3 additions & 4 deletions Scripts/TestAll
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash
set -e

swift --version
swift build -c release
for f in .build/release/*Tests; do
$f
done
swift build -c release --build-tests
swift test -c release --skip-build
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import Base64

struct Base64Test
extension Encoding
{
let name:String
let degenerate:String?
let canonical:String
let expected:[UInt8]

init(name:String,
degenerate:String? = nil,
canonical:String,
expected:[UInt8])
struct TestCase
{
self.name = name
self.degenerate = degenerate
self.canonical = canonical
self.expected = expected
let name:String
let degenerate:String?
let canonical:String
let expected:[UInt8]

init(name:String,
degenerate:String? = nil,
canonical:String,
expected:[UInt8])
{
self.name = name
self.degenerate = degenerate
self.canonical = canonical
self.expected = expected
}
}
}
extension Base64Test
extension Encoding.TestCase
{
init<UTF8>(name:String,
degenerate:String? = nil,
Expand Down
136 changes: 136 additions & 0 deletions Sources/Base64Tests/Encoding.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import Base64
import Testing

@Suite
struct Encoding
{
private
static let binary:[TestCase] = [
.init(name: "all",
degenerate:
"""
AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4v\
MDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5f\
YGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6P\
kJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/\
wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v\
8PHy8/T19vf4+fr7/P3+/w
""",
canonical:
"""
AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4v\
MDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5f\
YGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6P\
kJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/\
wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v\
8PHy8/T19vf4+fr7/P3+/w==
""",
expected: 0x00 ... 0xff),

.init(name: "reversed",
degenerate:
"""
//79/Pv6+fj39vX08/Lx8O/u7ezr6uno5+bl5OPi4eDf3t3c29rZ2NfW1dTT0tHQ\
z87NzMvKycjHxsXEw8LBwL++vby7urm4t7a1tLOysbCvrq2sq6qpqKempaSjoqGg\
n56dnJuamZiXlpWUk5KRkI+OjYyLiomIh4aFhIOCgYB/fn18e3p5eHd2dXRzcnFw\
b25tbGtqaWhnZmVkY2JhYF9eXVxbWllYV1ZVVFNSUVBPTk1MS0pJSEdGRURDQkFA\
Pz49PDs6OTg3NjU0MzIxMC8uLSwrKikoJyYlJCMiISAfHh0cGxoZGBcWFRQTEhEQ\
Dw4NDAsKCQgHBgUEAwIBAA
""",
canonical:
"""
//79/Pv6+fj39vX08/Lx8O/u7ezr6uno5+bl5OPi4eDf3t3c29rZ2NfW1dTT0tHQ\
z87NzMvKycjHxsXEw8LBwL++vby7urm4t7a1tLOysbCvrq2sq6qpqKempaSjoqGg\
n56dnJuamZiXlpWUk5KRkI+OjYyLiomIh4aFhIOCgYB/fn18e3p5eHd2dXRzcnFw\
b25tbGtqaWhnZmVkY2JhYF9eXVxbWllYV1ZVVFNSUVBPTk1MS0pJSEdGRURDQkFA\
Pz49PDs6OTg3NjU0MzIxMC8uLSwrKikoJyYlJCMiISAfHh0cGxoZGBcWFRQTEhEQ\
Dw4NDAsKCQgHBgUEAwIBAA==
""",
expected: (0x00 ... 0xff).reversed()),
]

private
static let string:[TestCase] = [
.init(name: "empty",
canonical: "",
expected: ""),

.init(name: "single",
degenerate: "YQ",
canonical: "YQ==",
expected: "a"),

.init(name: "double",
degenerate: "YWI",
canonical: "YWI=",
expected: "ab"),

.init(name: "triple",
canonical: "YWJj",
expected: "abc"),

.init(name: "basic",
canonical: "TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu",
expected: "Many hands make light work."),

.init(name: "whitespace",
degenerate:
"""
T\u{0C}WFueSBoY W5kc\ryBtYWt\tlIGxpZ2
h0IHd
vcmsu
""",
canonical: "TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu",
expected: "Many hands make light work."),

.init(name: "padding-11-16",
degenerate: "bGlnaHQgd29yay4",
canonical: "bGlnaHQgd29yay4=",
expected: "light work."),

.init(name: "padding-10-16",
degenerate: "bGlnaHQgd29yaw",
canonical: "bGlnaHQgd29yaw==",
expected: "light work"),

.init(name: "padding-9-12",
canonical: "bGlnaHQgd29y",
expected: "light wor"),

.init(name: "padding-8-12",
degenerate: "bGlnaHQgd28",
canonical: "bGlnaHQgd28=",
expected: "light wo"),

.init(name: "padding-7-12",
degenerate: "bGlnaHQgdw",
canonical: "bGlnaHQgdw==",
expected: "light w"),
]

@Test(arguments: Self.binary + Self.string)
static func defaultDigits(_ test:TestCase) throws
{
#expect(test.expected == Base64.decode(test.canonical.utf8, to: [UInt8].self))
#expect(test.canonical == Base64.encode(test.expected))

if let degenerate:String = test.degenerate
{
let decoded:[UInt8] = Base64.decode(degenerate, to: [UInt8].self)
let encoded:String = Base64.encode(decoded)
#expect(decoded == test.expected)
#expect(encoded == test.canonical)
}
}

@Test
static func urlSafeDigits()
{
let encoded:String = Base64.encode("<<???>>".utf8,
padding: false,
with: Base64.SafeDigits.self)

#expect(encoded == "PDw_Pz8-Pg")
}
}
Loading

0 comments on commit 5550cee

Please sign in to comment.