Refactor entire codebase and rewrite documentation
This commit is contained in:
@@ -1,41 +1,39 @@
|
||||
import Foundation
|
||||
|
||||
extension Connection {
|
||||
/// An encryption key for accessing an encrypted SQLite database.
|
||||
/// An encryption key for opening an encrypted SQLite database.
|
||||
///
|
||||
/// Used after the connection is opened to unlock the contents of the database.
|
||||
/// Two formats are supported: a passphrase with subsequent derivation, and
|
||||
/// a raw 256-bit key (32 bytes) without transformation.
|
||||
/// The key is applied after the connection is established to unlock the database contents.
|
||||
/// Two formats are supported:
|
||||
/// - a passphrase, which undergoes key derivation;
|
||||
/// - a raw 256-bit key (32 bytes) passed without transformation.
|
||||
public enum Key {
|
||||
/// A passphrase used to derive an encryption key.
|
||||
/// A human-readable passphrase used for key derivation.
|
||||
///
|
||||
/// Intended for human-readable strings such as passwords or PIN codes.
|
||||
/// The string is passed directly without escaping or quoting.
|
||||
/// The passphrase is supplied as-is and processed by the underlying key derivation
|
||||
/// mechanism configured in the database engine.
|
||||
case passphrase(String)
|
||||
|
||||
/// A raw 256-bit encryption key (32 bytes).
|
||||
///
|
||||
/// No key derivation is performed. The key is passed as-is and must be
|
||||
/// securely generated and stored.
|
||||
/// The key is passed directly to the database without derivation. It must be securely
|
||||
/// generated and stored.
|
||||
case rawKey(Data)
|
||||
|
||||
/// The string value to be passed to the database engine.
|
||||
/// The string value passed to the database engine.
|
||||
///
|
||||
/// For `.passphrase`, this is the raw string exactly as provided.
|
||||
/// For `.rawKey`, this is a hexadecimal literal in the format `X'...'`.
|
||||
/// For `.passphrase`, returns the passphrase exactly as provided.
|
||||
/// For `.rawKey`, returns a hexadecimal literal in the format `X'...'`.
|
||||
public var keyValue: String {
|
||||
switch self {
|
||||
case .passphrase(let string):
|
||||
return string
|
||||
string
|
||||
case .rawKey(let data):
|
||||
return data.sqliteLiteral
|
||||
data.sqliteLiteral
|
||||
}
|
||||
}
|
||||
|
||||
/// The length of the key value in bytes.
|
||||
///
|
||||
/// Returns the number of bytes in the UTF-8 encoding of `keyValue`,
|
||||
/// not the length of the original key or string.
|
||||
/// The number of bytes in the string representation of the key.
|
||||
public var length: Int32 {
|
||||
Int32(keyValue.utf8.count)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user