Skip to content

Commit

Permalink
UPDATED swift version to 5.9
Browse files Browse the repository at this point in the history
FIXED typos in names and strings
MINOR test improvement
  • Loading branch information
gal-yedidovich committed Apr 22, 2024
1 parent b15e520 commit dc31e82
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
4 changes: 2 additions & 2 deletions Sources/CBC/CBCError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal struct CBCError: LocalizedError {
case kCCParamError:
return "Illegal parameter value"
case kCCBufferTooSmall:
return "Insufficent buffer provided for specified operation"
return "Insufficient buffer provided for specified operation"
case kCCMemoryFailure:
return "Memory allocation failure"
case kCCAlignmentError:
Expand All @@ -36,7 +36,7 @@ internal struct CBCError: LocalizedError {
case kCCOverflow:
return "Overflow"
case kCCRNGFailure:
return "Rundom Number Generation Failure"
return "Random Number Generation Failure"
case kCCCallSequenceError:
return "Call Sequence Error"
case kCCKeySizeError:
Expand Down
8 changes: 4 additions & 4 deletions Sources/CBC/Cipher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ extension AES.CBC {

/// Initialize new cipher instance that can operate on data to either encrypt or decrypt it.
/// - Parameters:
/// - operation: the cryptografic operation
/// - operation: the cryptographic operation
/// - key: a symmetric key for operation
/// - iv: initial vector data
/// - Throws: when fails to create a cryptografic context
/// - Throws: when fails to create a cryptographic context
public init(_ operation: Operation, using key: SymmetricKey, iv: Data, options: CCOptions = pkcs7Padding) throws {
let keyData = key.dataRepresentation.bytes
let ivData = iv.bytes
Expand All @@ -34,7 +34,7 @@ extension AES.CBC {
}

context = cryptor
state = OpatationState()
state = OperationState()
}

/// releases the crypto context
Expand Down Expand Up @@ -67,7 +67,7 @@ fileprivate protocol CipherState {
func finalize(cipher: AES.CBC.Cipher, context: CCCryptorRef) throws -> Data
}

private class OpatationState: CipherState {
private class OperationState: CipherState {
private var buffer = Data()

func update(cipher: AES.CBC.Cipher, context: CCCryptorRef, _ data: Data) throws -> Data {
Expand Down
4 changes: 2 additions & 2 deletions Sources/CBC/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public extension SymmetricKey {
/// A Data instance created safely from the contiguous bytes without making any copies.
var dataRepresentation: Data {
return withUnsafeBytes { bytes in
let cfdata = CFDataCreateWithBytesNoCopy(nil, bytes.baseAddress?.assumingMemoryBound(to: UInt8.self), bytes.count, kCFAllocatorNull)
return (cfdata as Data?) ?? Data()
let cfData = CFDataCreateWithBytesNoCopy(nil, bytes.baseAddress?.assumingMemoryBound(to: UInt8.self), bytes.count, kCFAllocatorNull)
return (cfData as Data?) ?? Data()
}
}
}
6 changes: 3 additions & 3 deletions Sources/SimpleEncryptor/CryptoService/FileProcessing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func process(file src: URL, to dest: URL, using key: SymmetricKey, bufferSize: I
operation: Operation, finalOperation: FinalOperation? = nil,
onProgress: OnProgress?) async throws {
guard let fileSize = src.fileSize else {
throw ProccessingError.fileNotFound
throw ProcessingError.fileNotFound
}

try await safeStream(to: dest) { output in
Expand Down Expand Up @@ -53,7 +53,7 @@ private func safeStream(to dest: URL, operation: SafeStreamBlock) async throws {
let tempFile = tempDir.appendingPathComponent(UUID().uuidString)

guard let output = OutputStream(url: tempFile, append: false) else {
throw ProccessingError.failedToCreateOutputStream
throw ProcessingError.failedToCreateOutputStream
}

output.open()
Expand Down Expand Up @@ -83,7 +83,7 @@ extension OutputStream {
}
}

enum ProccessingError: LocalizedError {
enum ProcessingError: LocalizedError {
case fileNotFound
case failedToCreateOutputStream

Expand Down
25 changes: 19 additions & 6 deletions Tests/Tests/SimpleEncryptorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ class SimpleEncryptorTests: XCTestCase {

//When
//Then
do {
try await encryptor.encrypt(file: src, to: dest)
XCTFail("Should throw an error")
} catch {
XCTAssertEqual(error.localizedDescription, ProccessingError.fileNotFound.localizedDescription)
}
await assertThrows(try await encryptor.encrypt(file: src, to: dest), ProcessingError.fileNotFound)
}

@available(macOS 12.0, iOS 15.0, *)
Expand Down Expand Up @@ -162,3 +157,21 @@ fileprivate struct MockKeyService: KeyService {
try fetchResult.get()
}
}


private func assertThrows<T>(
_ expression: @autoclosure () async throws -> T,
message: String? = nil,
file: StaticString = #filePath,
line: UInt = #line,
_ expectedError: LocalizedError? = nil
) async {
do {
_ = try await expression()
XCTFail(message ?? "expression did not throw an error", file: file, line: line)
} catch {
if let expectedError {
XCTAssertEqual(error.localizedDescription, expectedError.localizedDescription)
}
}
}

0 comments on commit dc31e82

Please sign in to comment.