A small tool for storing passwords locally with git sync
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.6 KiB

3 months ago
use std::io;
3 months ago
static PASSWORD_TEST: &str = "MyPasswordStorage"; // will be added with nonce for storing each time
3 months ago
pub struct Encoder {
3 months ago
// will be stored with padding 32 bytes
3 months ago
passphrase: String
}
impl Encoder {
3 months ago
pub fn from(passphrase: &String) -> Encoder {
// TODO: throw error if password longer that 32 bytes
let padded_passphrase = Encoder::get_passhrase_with_padding(passphrase);
Encoder { passphrase: padded_passphrase }
}
fn get_passhrase_with_padding(passphrase: &String) -> String {
let mut result = passphrase.clone();
while result.len() < 32 {
// use '-' for padding, can be anything else
result.push('-');
}
result
3 months ago
}
// TODO: get by ref
3 months ago
pub fn encode(&self, line: &String) -> String {
return line.clone();
3 months ago
}
// TODO: review error type
pub fn decode(&self, line: String) -> io::Result<String> {
3 months ago
//.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
//match String::from_utf8(content) {
// Ok(s) => Ok(s),
// Err(e) => Err(io::Error::new(io::ErrorKind::InvalidData, e))
//}
return Ok(line.clone());
3 months ago
}
3 months ago
pub fn test_encoded_passphrase(&self, piassphrase_encoded: String) -> bool {
// TODO: implement
//self.passphrase == passphrase_encoded
// Encoder::get_encoded_test_passphrase();
return true;
3 months ago
}
pub fn get_encoded_test_passphrase(&self) -> String {
3 months ago
// TODO: use this
3 months ago
self.passphrase.clone()
}
}