Merge pull request #16 from keeshux/add-more-crypto-algorithms

Add more crypto algorithms
This commit is contained in:
Davide De Rosa 2018-09-06 12:18:39 +02:00 committed by GitHub
commit a54c767f57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 2 deletions

View File

@ -40,19 +40,25 @@ import Foundation
extension SessionProxy { extension SessionProxy {
/// The available encryption algorithms. /// The available encryption algorithms.
public enum Cipher: String, Codable { public enum Cipher: String, Codable, CustomStringConvertible {
// WARNING: must match OpenSSL algorithm names // WARNING: must match OpenSSL algorithm names
/// AES encryption with 128-bit key size and CBC. /// AES encryption with 128-bit key size and CBC.
case aes128cbc = "AES-128-CBC" case aes128cbc = "AES-128-CBC"
/// AES encryption with 192-bit key size and CBC.
case aes192cbc = "AES-192-CBC"
/// AES encryption with 256-bit key size and CBC. /// AES encryption with 256-bit key size and CBC.
case aes256cbc = "AES-256-CBC" case aes256cbc = "AES-256-CBC"
/// AES encryption with 128-bit key size and GCM. /// AES encryption with 128-bit key size and GCM.
case aes128gcm = "AES-128-GCM" case aes128gcm = "AES-128-GCM"
/// AES encryption with 192-bit key size and GCM.
case aes192gcm = "AES-192-GCM"
/// AES encryption with 256-bit key size and GCM. /// AES encryption with 256-bit key size and GCM.
case aes256gcm = "AES-256-GCM" case aes256gcm = "AES-256-GCM"
@ -60,18 +66,47 @@ extension SessionProxy {
public var embedsDigest: Bool { public var embedsDigest: Bool {
return rawValue.hasSuffix("-GCM") return rawValue.hasSuffix("-GCM")
} }
/// Returns a generic name for this cipher.
public var genericName: String {
return rawValue.hasSuffix("-GCM") ? "AES-GCM" : "AES-CBC"
}
/// :nodoc:
public var description: String {
return rawValue
}
} }
/// The available message digest algorithms. /// The available message digest algorithms.
public enum Digest: String, Codable { public enum Digest: String, Codable, CustomStringConvertible {
// WARNING: must match OpenSSL algorithm names // WARNING: must match OpenSSL algorithm names
/// SHA1 message digest. /// SHA1 message digest.
case sha1 = "SHA1" case sha1 = "SHA1"
/// SHA224 message digest.
case sha224 = "SHA224"
/// SHA256 message digest. /// SHA256 message digest.
case sha256 = "SHA256" case sha256 = "SHA256"
/// SHA256 message digest.
case sha384 = "SHA384"
/// SHA256 message digest.
case sha512 = "SHA512"
/// Returns a generic name for this digest.
public var genericName: String {
return "HMAC"
}
/// :nodoc:
public var description: String {
return "\(genericName)-\(rawValue)"
}
} }
/// The way to create a `SessionProxy.Configuration` object for a `SessionProxy`. /// The way to create a `SessionProxy.Configuration` object for a `SessionProxy`.