justinwongcn/moonpgp/api does not have a README file
pub struct DecryptionBuilder {
// private fields
}fn DecryptionBuilder::decryption_key(self : DecryptionBuilder, key : PrivateKey) -> DecryptionBuilderfn DecryptionBuilder::verification_key(self : DecryptionBuilder, key : PublicKey) -> DecryptionBuilderpub struct EncryptionBuilder {
// private fields
}fn EncryptionBuilder::compress(self : EncryptionBuilder, algo : CompressedAlgo) -> EncryptionBuilderfn EncryptionBuilder::password_v6(self : EncryptionBuilder, pass : String, aead? : AeadMode, argon2? : Bool, passes? : Int, parallelism? : Int, memory_exp? : Int) -> EncryptionBuilderpub struct KeyGenBuilder {
// private fields
}fn KeyRing::find_encryption_key(self : KeyRing, key_id : BytesView, now? : Int64) -> PublicKeyPacket? raisepub struct Pgp {
}test "builder chain seals a payload" {
let seal = @api.pgp()
.encryption()
.password("hunter2")
.file_name("msg.txt")
.finish()
let armored = seal(b"payload")
inspect(armored.has_prefix("-----BEGIN PGP MESSAGE-----"), content="true")
}pub struct PrivateKey {
primary : SecretKeyPacket
user_ids : Array[UserIdBinding]
direct_signature : SignaturePacket?
subkeys : Array[SecretSubkeyCert]
revocations : Array[SignaturePacket]
} derive(Debug)fn PrivateKey::apply_revocation_certificate(self : PrivateKey, armored : String) -> PrivateKey raisetest "armor round trip preserves the fingerprint" {
let key = @api.generate_ed25519_key("A <a@example.com>")
let re = @api.PrivateKey::from_armored(key.to_armored())
assert_eq(re.fingerprint(), key.fingerprint())
}fn PrivateKey::lock_argon2(self : PrivateKey, passphrase : String, passes? : Int, parallelism? : Int, memory_exp? : Int) -> PrivateKey raisefn PrivateKey::revoke_user_id(self : PrivateKey, user_id : String, message? : String, created? : Int) -> PrivateKey raisetest "an expiry is visible through the lifecycle checks" {
let key = @api.generate_ed25519_key("E <e@example.com>").set_expiry(3600)
let now = @primitives.unix_now()
assert_false(key.is_expired(now))
assert_true(key.is_expired(now + 3601))
}fn PrivateKey::set_primary_user_id(self : PrivateKey, user_id : String, created? : Int) -> PrivateKey raisefn PrivateKey::set_subkey_expiry(self : PrivateKey, subkey_id : BytesView, seconds : Int64, created? : Int) -> PrivateKey raisefn PrivateKey::unlock(self : PrivateKey, passphrase : String, argon2_max_memory_kib? : Int) -> PrivateKey raisetest "unlock raises the typed WrongPassphrase error" {
let key = @api.generate_ed25519_key("A <a@example.com>").lock("correct horse")
try {
let _ = key.unlock("wrong horse")
fail("unlocking with the wrong passphrase must fail")
} catch {
@error.WrongPassphrase(_) => () // the expected failure class
_ => fail("expected WrongPassphrase")
}
}pub struct PublicKey {
primary : PublicKeyPacket
user_ids : Array[UserIdBinding]
direct_signature : SignaturePacket?
subkeys : Array[SubkeyCert]
revocations : Array[SignaturePacket]
} derive(Debug)pub(all) struct SecretSubkeyCert {
secret : SecretKeyPacket
binding : SignaturePacket
revocation : SignaturePacket?
} derive(Debug)pub(all) struct SubkeyCert {
key : PublicKeyPacket
binding : SignaturePacket
revocation : SignaturePacket?
} derive(Debug)pub(all) struct UserIdBinding {
user_id : String
self_signature : SignaturePacket
revocation : SignaturePacket?
} derive(Debug)pub(all) struct V6Password {
passphrase : String
aead : AeadMode
argon2 : Bool
passes : Int
parallelism : Int
memory_exp : Int
}let DEFAULT_MAX_DECOMPRESSED_BYTES : Intfn decrypt_and_verify(message : String, decryption_keys : Array[PrivateKey], verifier : PublicKey?, max_decompressed? : Int) -> (Bytes, VerifyStatus) raisefn decrypt_binary_with_password(data : BytesView, passphrase : String, argon2_max_memory_kib? : Int, max_decompressed? : Int) -> Bytes raisefn decrypt_binary_with_private_key(data : BytesView, key : PrivateKey, max_decompressed? : Int) -> Bytes raisefn decrypt_with_password(message : String, passphrase : String, argon2_max_memory_kib? : Int, max_decompressed? : Int) -> Bytes raisefn decrypt_with_private_key(message : String, key : PrivateKey, max_decompressed? : Int) -> Bytes raisefn encrypt_to_recipients(plaintext : BytesView, recipients : Array[PublicKey], file_name? : String, compress? : CompressedAlgo) -> String raisefn encrypt_to_session_key(plaintext : BytesView, sk : SessionKey, file_name? : String, compress? : CompressedAlgo) -> String raisefn encrypt_with_password(plaintext : BytesView, passphrase : String, file_name? : String, aead? : Bool, argon2? : Bool, argon2_memory_exp? : Int, compress? : CompressedAlgo) -> String raisetest "password encryption round trip" {
let armored = @api.encrypt_with_password(b"Hello, world!", "hunter2")
inspect(armored.has_prefix("-----BEGIN PGP MESSAGE-----"), content="true")
assert_eq(@api.decrypt_with_password(armored, "hunter2"), b"Hello, world!")
}fn encrypt_with_password_argon2(plaintext : BytesView, passphrase : String, file_name? : String, passes? : Int, parallelism? : Int, memory_exp? : Int, compress? : CompressedAlgo) -> String raisefn encrypt_with_password_v6(plaintext : BytesView, passphrase : String, file_name? : String, aead? : AeadMode, argon2? : Bool, passes? : Int, parallelism? : Int, memory_exp? : Int, compress? : CompressedAlgo) -> String raisetest "generate an ed25519 key" {
let key = @api.generate_ed25519_key("A <a@example.com>")
assert_eq(key.user_id(), "A <a@example.com>")
inspect(key.fingerprint().length(), content="20")
}fn generate_revocation_certificate(key : PrivateKey, reason? : RevocationReason, message? : String, created? : Int) -> String raisetest "a revocation certificate is armored" {
let key = @api.generate_ed25519_key("A <a@example.com>")
let cert = @api.generate_revocation_certificate(key)
inspect(
cert.has_prefix("-----BEGIN PGP PUBLIC KEY BLOCK-----"),
content="true",
)
}fn recover_session_key_with_password(message : String, passphrase : String, argon2_max_memory_kib? : Int) -> SessionKey raisefn revoke_key(key : PrivateKey, reason? : RevocationReason, message? : String, created? : Int) -> PrivateKey raisefn revoke_subkey(key : PrivateKey, subkey_id : BytesView, reason? : RevocationReason, message? : String, created? : Int) -> PrivateKey raisefn sign_and_encrypt(data : BytesView, signer : PrivateKey, recipients : Array[PublicKey], text_mode? : Bool, compress? : CompressedAlgo, created? : Int, file_name? : String) -> String raisefn sign_cleartext_with(text : String, key : PrivateKey, hash : HashId, created? : Int) -> String raisefn sign_detached(data : BytesView, key : PrivateKey, text_mode? : Bool, created? : Int) -> String raisetest "detached signature round trip" {
let key = @api.generate_ed25519_key("A <a@example.com>")
let sig = @api.sign_detached(b"payload", key)
inspect(sig.has_prefix("-----BEGIN PGP SIGNATURE-----"), content="true")
assert_eq(
@api.verify_detached(b"payload", sig, key.to_public()),
@api.VerifyStatus::Ok,
)
assert_true(@api.verify_detached(b"tampered", sig, key.to_public()) is Failed)
}fn sign_inline(data : BytesView, key : PrivateKey, text_mode? : Bool, created? : Int, file_name? : String) -> String raisefn verify_detached(data : BytesView, armored_signature : String, verifier : PublicKey) -> VerifyStatus raisefn verify_inline(message : String, verifier : PublicKey, max_decompressed? : Int) -> (Bytes, VerifyStatus) raisefn verify_key_signature(sig : SignaturePacket, signer_pub : PublicKeyPacket, certified_pub : PublicKeyPacket, user_id? : String, direct? : Bool) -> Bool raiseInstall
Download zipPure-MoonBit OpenPGP implementation (RFC 4880/9580): email encryption, decryption, signing and verification, interoperable with GnuPG and gopenpgp.