1use crate::core::word_dictionary::WordDictionary;
17
18pub const BIP39_ENGLISH: &str = include_str!("../../dictionaries/word/security/bip39-english.txt");
22
23pub const EFF_LONG: &str = include_str!("../../dictionaries/word/security/eff-long.txt");
26
27pub const EFF_SHORT1: &str = include_str!("../../dictionaries/word/security/eff-short1.txt");
30
31pub const EFF_SHORT2: &str = include_str!("../../dictionaries/word/security/eff-short2.txt");
34
35pub const DICEWARE: &str = include_str!("../../dictionaries/word/security/diceware.txt");
38
39pub const PGP_EVEN: &str = include_str!("../../dictionaries/word/security/pgp-even.txt");
42
43pub const PGP_ODD: &str = include_str!("../../dictionaries/word/security/pgp-odd.txt");
46
47pub const NATO: &str = include_str!("../../dictionaries/word/fun/nato.txt");
51
52pub const BUZZWORDS: &str = include_str!("../../dictionaries/word/fun/buzzwords.txt");
55
56pub const KLINGON: &str = include_str!("../../dictionaries/word/fun/klingon.txt");
59
60pub const POKEMON: &str = include_str!("../../dictionaries/word/fun/pokemon.txt");
63
64pub fn bip39_english() -> WordDictionary {
80 WordDictionary::builder()
81 .words_from_str(BIP39_ENGLISH)
82 .delimiter(" ")
83 .case_sensitive(false)
84 .build()
85 .expect("BIP-39 English word list should be valid")
86}
87
88pub fn eff_long() -> WordDictionary {
90 WordDictionary::builder()
91 .words_from_str(EFF_LONG)
92 .delimiter(" ")
93 .case_sensitive(false)
94 .build()
95 .expect("EFF Long word list should be valid")
96}
97
98pub fn eff_short1() -> WordDictionary {
100 WordDictionary::builder()
101 .words_from_str(EFF_SHORT1)
102 .delimiter(" ")
103 .case_sensitive(false)
104 .build()
105 .expect("EFF Short 1 word list should be valid")
106}
107
108pub fn eff_short2() -> WordDictionary {
110 WordDictionary::builder()
111 .words_from_str(EFF_SHORT2)
112 .delimiter(" ")
113 .case_sensitive(false)
114 .build()
115 .expect("EFF Short 2 word list should be valid")
116}
117
118pub fn diceware() -> WordDictionary {
120 WordDictionary::builder()
121 .words_from_str(DICEWARE)
122 .delimiter(" ")
123 .case_sensitive(false)
124 .build()
125 .expect("Diceware word list should be valid")
126}
127
128pub fn pgp_even() -> WordDictionary {
130 WordDictionary::builder()
131 .words_from_str(PGP_EVEN)
132 .delimiter("-")
133 .case_sensitive(false)
134 .build()
135 .expect("PGP Even word list should be valid")
136}
137
138pub fn pgp_odd() -> WordDictionary {
140 WordDictionary::builder()
141 .words_from_str(PGP_ODD)
142 .delimiter("-")
143 .case_sensitive(false)
144 .build()
145 .expect("PGP Odd word list should be valid")
146}
147
148pub fn nato() -> WordDictionary {
150 WordDictionary::builder()
151 .words_from_str(NATO)
152 .delimiter("-")
153 .case_sensitive(false)
154 .build()
155 .expect("NATO word list should be valid")
156}
157
158pub fn buzzwords() -> WordDictionary {
160 WordDictionary::builder()
161 .words_from_str(BUZZWORDS)
162 .delimiter(" ")
163 .case_sensitive(false)
164 .build()
165 .expect("Buzzwords word list should be valid")
166}
167
168pub fn klingon() -> WordDictionary {
170 WordDictionary::builder()
171 .words_from_str(KLINGON)
172 .delimiter(" ")
173 .case_sensitive(true) .build()
175 .expect("Klingon word list should be valid")
176}
177
178pub fn pokemon() -> WordDictionary {
180 WordDictionary::builder()
181 .words_from_str(POKEMON)
182 .delimiter(" ")
183 .case_sensitive(false)
184 .build()
185 .expect("Pokemon word list should be valid")
186}
187
188#[cfg(test)]
189mod tests {
190 use super::*;
191
192 #[test]
193 fn test_bip39_english_word_count() {
194 let dict = bip39_english();
195 assert_eq!(dict.base(), 2048);
196 }
197
198 #[test]
199 fn test_bip39_english_first_word() {
200 let dict = bip39_english();
201 assert_eq!(dict.encode_word(0), Some("abandon"));
202 }
203
204 #[test]
205 fn test_bip39_english_last_word() {
206 let dict = bip39_english();
207 assert_eq!(dict.encode_word(2047), Some("zoo"));
208 }
209
210 #[test]
211 fn test_bip39_english_roundtrip() {
212 use crate::encoders::algorithms::word;
213
214 let dict = bip39_english();
215 let data = b"The quick brown fox jumps over the lazy dog";
216 let encoded = word::encode(data, &dict);
217 let decoded = word::decode(&encoded, &dict).unwrap();
218 assert_eq!(decoded, data);
219 }
220
221 #[test]
222 fn test_bip39_english_case_insensitive() {
223 let dict = bip39_english();
224 assert_eq!(dict.decode_word("abandon"), Some(0));
225 assert_eq!(dict.decode_word("ABANDON"), Some(0));
226 assert_eq!(dict.decode_word("Abandon"), Some(0));
227 }
228}