[Upd] mtp update

This commit is contained in:
Alex Emmet 2026-07-20 15:28:15 +02:00
commit f82500ea7d
24 changed files with 2535 additions and 1800 deletions

View file

@ -4,8 +4,9 @@ version = "0.1.0"
edition = "2024"
[dependencies]
mtp = { git = "https://git.methanium.net/Methanium/mtp.git" }
mtp-crypto = { git = "https://git.methanium.net/Methanium/mtp.git", features = ["pqc"] }
mtp = { git = "https://git.methanium.net/Methanium/mtp.git", features = [
"crypto"
] }
reqwest = "0.13.2"
tokio = { version = "1.50.0", features = ["full"] }

View file

@ -1,5 +1,5 @@
use base64::{Engine as _, engine::general_purpose::STANDARD};
use mtp_crypto::{Keyring, PublicKeyBundle};
use mtp::crypto::{Keyring, PublicKeyBundle};
pub fn generate_keyring() -> Keyring {
Keyring::generate()
@ -24,5 +24,5 @@ pub fn public_key_bundle_from_base64(s: &str) -> Option<PublicKeyBundle> {
}
pub fn hex_hash(input: &str) -> String {
hex::encode(mtp_crypto::sha256(input.as_bytes()))
hex::encode(mtp::crypto::sha256(input.as_bytes()))
}

View file

@ -1,5 +1,5 @@
use base64::{Engine as _, engine::general_purpose::STANDARD};
use mtp_crypto::{EncryptionType, Keyring, PublicKeyBundle, encrypt_for, decrypt_with};
use mtp::crypto::{EncryptionType, Keyring, PublicKeyBundle, decrypt_with, encrypt_for};
#[derive(Clone, Copy, Debug)]
pub enum DataFormat {
@ -22,13 +22,8 @@ pub fn encrypt(
.map_err(|e| format!("encryption error: {:?}", e))
}
pub fn decrypt(
ciphertext: &[u8],
aad: &[u8],
keyring: &Keyring,
) -> Result<Vec<u8>, String> {
decrypt_with(ciphertext, keyring, aad)
.map_err(|e| format!("decryption error: {:?}", e))
pub fn decrypt(ciphertext: &[u8], aad: &[u8], keyring: &Keyring) -> Result<Vec<u8>, String> {
decrypt_with(ciphertext, keyring, aad).map_err(|e| format!("decryption error: {:?}", e))
}
pub fn encrypt_challenge(
@ -39,12 +34,10 @@ pub fn encrypt_challenge(
Ok(STANDARD.encode(&blob))
}
pub fn decrypt_challenge(
encrypted: &str,
keyring: &Keyring,
) -> Result<String, String> {
let blob =
STANDARD.decode(encrypted).map_err(|e| format!("base64 decode error: {}", e))?;
pub fn decrypt_challenge(encrypted: &str, keyring: &Keyring) -> Result<String, String> {
let blob = STANDARD
.decode(encrypted)
.map_err(|e| format!("base64 decode error: {}", e))?;
let pt = decrypt(&blob, b"challenge", keyring)?;
String::from_utf8(pt).map_err(|e| format!("utf8 decode error: {}", e))
}