Remove key error enum

This commit is contained in:
Christoph Hagen 2023-12-06 09:53:24 +01:00
parent b2b3c74586
commit ac22fcd4eb

View File

@ -17,11 +17,6 @@ private let df: DateFormatter = {
return df return df
}() }()
enum ServerError: Error {
case invalidAuthenticationFileContent
case invalidAuthenticationToken
}
// configures your application // configures your application
public func configure(_ app: Application) async throws { public func configure(_ app: Application) async throws {
let storageFolder = URL(fileURLWithPath: app.directory.resourcesDirectory) let storageFolder = URL(fileURLWithPath: app.directory.resourcesDirectory)
@ -79,15 +74,15 @@ private func loadKeys(at url: URL) throws -> (deviceKey: Data, remoteKey: Data)
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
.map { .map {
guard let key = Data(fromHexEncodedString: $0) else { guard let key = Data(fromHexEncodedString: $0) else {
throw ServerError.invalidAuthenticationToken fatalError("Invalid key data: Failed to convert hex to binary.")
} }
guard key.count == SHA256.byteCount else { guard key.count == SHA256.byteCount else {
throw ServerError.invalidAuthenticationToken fatalError("Invalid key data: Length should be \(SHA256.byteCount), not \(key.count)")
} }
return key return key
} }
guard authContent.count == 2 else { guard authContent.count == 2 else {
throw ServerError.invalidAuthenticationFileContent fatalError("Invalid keys: Expected 2, found \(authContent.count)")
} }
return (deviceKey: authContent[0], remoteKey: authContent[1]) return (deviceKey: authContent[0], remoteKey: authContent[1])
} }