Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Sources/SFrame/MLS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ public enum MLSError: Error {
case contextOverflow
/// Epoch bits must be 0 < x < 64.
case badEpochBits

public var localizedDescription: String {
switch self {
case .unknownEpoch:
return "Unknown epoch."

case .senderOverflow:
return "Sender ID exceeds maximum allowed."

case .contextOverflow:
return "Context ID exceeds maximum allowed."

case .badEpochBits:
return "Epoch bits must be between 1 and 63."
}
}
}

/// Provides an interface to utilize SFrame with MLS keying.
Expand Down
7 changes: 7 additions & 0 deletions Sources/SFrame/Provider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ public protocol CryptoProvider {
public enum CryptoProviderError: Error {
/// This provider does not support the requested cipher suite.
case unsupportedCipherSuite

public var localizedDescription: String {
switch self {
case .unsupportedCipherSuite:
return "This provider does not support the requested cipher suite."
}
}
}
17 changes: 16 additions & 1 deletion Sources/SFrame/SFrame.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,22 @@ public enum SFrameError: Error {
case existingKey
case badParameter
case malformedCipherText
case keyMisuse

public var localizedDescription: String {
switch self {
case .missingKey:
return "The required key is missing."

case .existingKey:
return "This key already exists."

case .badParameter:
return "A bit size parameter was invalid."

case .malformedCipherText:
return "The ciphertext is malformed."
}
}
}

/// The operation this key is to be used for.
Expand Down
13 changes: 13 additions & 0 deletions Sources/SFrame/SyntheticAEAD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ public enum SyntheticAEADError: Error {
case missingKeySize
case authenticationFailure
case badKeySize

public var localizedDescription: String {
switch self {
case .missingKeySize:
return "The cipher suite does not specify a key size."

case .authenticationFailure:
return "Authentication failed."

case .badKeySize:
return "The provided key size does not match the cipher suite requirements."
}
}
}

/// SFrame AES-CTR with SHA2 implementation.
Expand Down
15 changes: 11 additions & 4 deletions Sources/SFrame/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@

import Foundation

public enum DataError: Error {
case lengthMismatch
}

// SealedBox implementation.
internal struct SealedDataBox: SealedBox {
internal let authTag: Data
internal let encrypted: Data
internal let nonceBytes: Data
}

public enum DataError: Error {
case lengthMismatch

public var localizedDescription: String {
switch self {
case .lengthMismatch:
return "XOR requires buffers of equal length."
}
}
}

extension Data {
/// Initialize a view into a contiguous byte buffer.
/// - Parameter bytes: The contiguous byte buffer to expose a view into.
Expand Down
10 changes: 10 additions & 0 deletions Tests/SFrameTests/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ internal func hexToData(_ hex: String) -> Data {
internal enum TestError: Error {
case missingVectors
case unsupportedCipherSuite

internal var localizedDescription: String {
switch self {
case .missingVectors:
return "Test vectors are missing."

case .unsupportedCipherSuite:
return "The cipher suite is not supported."
}
}
}

internal func loadTestVectors() throws -> TestVectors {
Expand Down