Files
ShhShell/ShhShell/Keys/Keypair.swift
neon443 80b83644b4 updated keypair data structure to have an name, passphrase and type
added generateKy to generate a key, currently only rsa
update generateRSA to return the Data for pub and priv, and take a custom size
bell animation better, slightly longer in total and easeinout
added new generate button hardcoded to a rsa 4096
added keytype to define key types (duh)
update getKeys to use the new keypair structure
2025-06-30 16:31:01 +01:00

52 lines
1.1 KiB
Swift

//
// Keypair.swift
// ShhShell
//
// Created by neon443 on 25/06/2025.
//
import Foundation
protocol KeypairProtocol: Identifiable, Equatable, Codable, Hashable {
var id: UUID { get }
var type: KeyType { get set }
var name: String { get set }
var publicKey: Data? { get set }
var privateKey: Data? { get set }
var passphrase: String { get set }
}
struct Keypair: KeypairProtocol {
var id = UUID()
var type: KeyType = .rsa(4096)
var name: String = ""
var publicKey: Data?
var privateKey: Data?
var passphrase: String = ""
init(
id: UUID = UUID(),
type: KeyType,
name: String,
publicKey: String,
privateKey: String,
passphrase: String = ""
) {
self.id = id
self.type = type
self.name = name
self.publicKey = publicKey.data(using: .utf8)
self.privateKey = privateKey.data(using: .utf8)
self.passphrase = passphrase
}
static func ==(lhs: Keypair, rhs: Keypair) -> Bool {
if lhs.publicKey?.base64EncodedString() == rhs.publicKey?.base64EncodedString()
&& lhs.privateKey?.base64EncodedString() == rhs.privateKey?.base64EncodedString() {
return true
} else {
return false
}
}
}