mod algo;
pub use crate::plugins::skeyotp::algo::SKEY_OTP_INSTRUCTIONS;
use crate::plugins::skeyotp::algo::{bytes_to_wordlist, max_word_len, wordlist_to_bytes};
use crate::plugins::{GenerationError, HardCopyGenerator, LibPlugin, SoftCopyGenerator};
use crate::{
HardCopy, HardCopyInput, HardCopySection, HardCopySectionContent, SoftCopy, SoftCopyInput,
};
const WORDS_PER_LINE: usize = 6;
pub struct SKeyOtpPlugin;
const PLUGIN_NAME: &str = "S/KEY OTP";
const PLUGIN_DESCRIPTION: &str = "Wordlist generation using S/KEY OTP words (RFC 2289).";
impl LibPlugin for SKeyOtpPlugin {
fn name(&self) -> String {
PLUGIN_NAME.to_string()
}
fn description(&self) -> String {
PLUGIN_DESCRIPTION.to_string()
}
fn instructions(&self) -> String {
SKEY_OTP_INSTRUCTIONS.to_string()
}
}
impl HardCopyGenerator for SKeyOtpPlugin {
fn generate_hard_copy(&self, softinput: &SoftCopyInput) -> Result<HardCopy, GenerationError> {
let words = bytes_to_wordlist(softinput.to_bytes());
let col_width = max_word_len();
let lines: Vec<String> = words
.chunks(WORDS_PER_LINE)
.enumerate()
.map(|(i, chunk)| {
let padded: Vec<String> = chunk
.iter()
.map(|w| format!("{:width$}", w, width = col_width))
.collect();
format!("{:04}: {}", i + 1, padded.join(" "))
})
.collect();
let mut hardcopy = HardCopy::new();
hardcopy.push(HardCopySection {
name: PLUGIN_NAME.to_string(),
content: HardCopySectionContent::Words(lines),
});
Ok(hardcopy)
}
}
impl SoftCopyGenerator for SKeyOtpPlugin {
fn generate_soft_copy(&self, input: &mut HardCopyInput) -> Result<SoftCopy, GenerationError> {
let word_refs: Vec<&str> = input.words().iter().map(String::as_str).collect();
let bytes = wordlist_to_bytes(&word_refs);
Ok(SoftCopy { bytes })
}
}