Browse Source

Throw error instead of fatal error

Marcin Krzyzanowski 1 year ago
parent
commit
aa90fb447c

+ 6 - 1
Sources/CryptoSwift/BlockDecryptor.swift

@@ -13,6 +13,11 @@
 //
 
 public class BlockDecryptor: Cryptor, Updatable {
+
+  public enum Error: Swift.Error {
+    case unsupported
+  }
+
   @usableFromInline
   let blockSize: Int
 
@@ -87,7 +92,7 @@ public class BlockDecryptor: Cryptor, Updatable {
 
   public func seek(to position: Int) throws {
     guard var worker = self.worker as? SeekableModeWorker else {
-      fatalError("Not supported")
+      throw Error.unsupported
     }
 
     try worker.seek(to: position)

+ 6 - 1
Sources/CryptoSwift/BlockEncryptor.swift

@@ -14,6 +14,11 @@
 
 @usableFromInline
 final class BlockEncryptor: Cryptor, Updatable {
+
+  public enum Error: Swift.Error {
+    case unsupported
+  }
+
   private let blockSize: Int
   private var worker: CipherModeWorker
   private let padding: Padding
@@ -57,6 +62,6 @@ final class BlockEncryptor: Cryptor, Updatable {
 
   @usableFromInline
   func seek(to: Int) throws {
-    fatalError("Not supported")
+    throw Error.unsupported
   }
 }

+ 6 - 1
Sources/CryptoSwift/StreamDecryptor.swift

@@ -15,6 +15,11 @@
 @usableFromInline
 final class StreamDecryptor: Cryptor, Updatable {
 
+  @usableFromInline
+  enum Error: Swift.Error {
+    case unsupported
+  }
+
   @usableFromInline
   internal let blockSize: Int
 
@@ -83,7 +88,7 @@ final class StreamDecryptor: Cryptor, Updatable {
   @inlinable
   public func seek(to position: Int) throws {
     guard var worker = self.worker as? SeekableModeWorker else {
-      fatalError("Not supported")
+      throw Error.unsupported
     }
 
     try worker.seek(to: position)

+ 6 - 1
Sources/CryptoSwift/StreamEncryptor.swift

@@ -15,6 +15,11 @@
 @usableFromInline
 final class StreamEncryptor: Cryptor, Updatable {
 
+  @usableFromInline
+  enum Error: Swift.Error {
+    case unsupported
+  }
+
   @usableFromInline
   internal let blockSize: Int
 
@@ -63,6 +68,6 @@ final class StreamEncryptor: Cryptor, Updatable {
 
   @usableFromInline
   func seek(to: Int) throws {
-    fatalError("Not supported")
+    throw Error.unsupported
   }
 }