keeper_secrets_manager_core/
enums.rs

1// -*- coding: utf-8 -*-
2//  _  __
3// | |/ /___ ___ _ __  ___ _ _ (R)
4// | ' </ -_) -_) '_ \/ -_) '_|
5// |_|\_\___\___| .__/\___|_|
6//              |_|
7//
8// Keeper Secrets Manager
9// Copyright 2024 Keeper Security Inc.
10// Contact: sm@keepersecurity.com
11//
12
13use crate::{
14    config_keys::ConfigKeys,
15    custom_error::KSMRError,
16    storage::{FileKeyValueStorage, InMemoryKeyValueStorage, KeyValueStorage},
17};
18use serde_json::Value;
19use std::fmt;
20use std::collections::HashMap;
21
22pub enum KvStoreType {
23    File(FileKeyValueStorage),
24    InMemory(InMemoryKeyValueStorage),
25    None,
26}
27
28pub struct KeyValueStore {
29    store: KvStoreType,
30}
31
32impl KeyValueStore {
33    pub fn new(store_type: KvStoreType) -> Self {
34        KeyValueStore { store: store_type }
35    }
36}
37
38impl KeyValueStorage for KeyValueStore {
39    fn read_storage(&self) -> Result<HashMap<ConfigKeys, String>, KSMRError> {
40        self.store.read_storage()
41    }
42
43    fn save_storage(
44        &mut self,
45        updated_config: HashMap<ConfigKeys, String>,
46    ) -> Result<bool, KSMRError> {
47        self.store.save_storage(updated_config)
48    }
49
50    fn get(&self, key: ConfigKeys) -> Result<Option<String>, KSMRError> {
51        self.store.get(key)
52    }
53
54    fn set(
55        &mut self,
56        key: ConfigKeys,
57        value: String,
58    ) -> Result<HashMap<ConfigKeys, String>, KSMRError> {
59        self.store.set(key, value)
60    }
61
62    fn delete(&mut self, key: ConfigKeys) -> Result<HashMap<ConfigKeys, String>, KSMRError> {
63        self.store.delete(key)
64    }
65
66    fn delete_all(&mut self) -> Result<HashMap<ConfigKeys, String>, KSMRError> {
67        self.store.delete_all()
68    }
69
70    fn contains(&self, key: ConfigKeys) -> Result<bool, KSMRError> {
71        self.store.contains(key)
72    }
73
74    fn create_config_file_if_missing(&self) -> Result<(), KSMRError> {
75        self.store.create_config_file_if_missing()
76    }
77
78    fn is_empty(&self) -> Result<bool, KSMRError> {
79        self.store.is_empty()
80    }
81}
82
83impl Clone for KvStoreType {
84    fn clone(&self) -> Self {
85        match self {
86            KvStoreType::InMemory(inner) => KvStoreType::InMemory((*inner).clone()),
87            KvStoreType::File(inner) => KvStoreType::File((*inner).clone()),
88            KvStoreType::None => KvStoreType::None,
89        }
90    }
91}
92
93impl KeyValueStorage for KvStoreType {
94    fn read_storage(&self) -> Result<HashMap<ConfigKeys, String>, KSMRError> {
95        match &self {
96            KvStoreType::File(file_store) => file_store.read_storage(),
97            KvStoreType::InMemory(in_memory_store) => in_memory_store.read_storage(),
98            KvStoreType::None => {
99                let kv_store = FileKeyValueStorage::new(None);
100                match kv_store {
101                    Ok(file_store) => file_store.read_storage(),
102                    Err(e) => Err(e),
103                }
104            }
105        }
106    }
107
108    fn save_storage(
109        &mut self,
110        updated_config: HashMap<ConfigKeys, String>,
111    ) -> Result<bool, KSMRError> {
112        match self {
113            KvStoreType::File(file_store) => file_store.save_storage(updated_config),
114            KvStoreType::InMemory(in_memory_store) => in_memory_store.save_storage(updated_config),
115            KvStoreType::None => Err(KSMRError::StorageError("No storage available".to_string())),
116        }
117    }
118
119    fn get(&self, key: ConfigKeys) -> Result<Option<String>, KSMRError> {
120        match &self {
121            KvStoreType::File(file_store) => file_store.get(key),
122            KvStoreType::InMemory(in_memory_store) => in_memory_store.get(key),
123            KvStoreType::None => Ok(None),
124        }
125    }
126
127    fn set(
128        &mut self,
129        key: ConfigKeys,
130        value: String,
131    ) -> Result<HashMap<ConfigKeys, String>, KSMRError> {
132        match self {
133            KvStoreType::File(file_store) => file_store.set(key, value),
134            KvStoreType::InMemory(in_memory_store) => in_memory_store.set(key, value),
135            KvStoreType::None => Err(KSMRError::StorageError(
136                "No storage available when None is type here".to_string(),
137            )),
138        }
139    }
140
141    fn delete(&mut self, key: ConfigKeys) -> Result<HashMap<ConfigKeys, String>, KSMRError> {
142        match self {
143            KvStoreType::File(file_store) => file_store.delete(key),
144            KvStoreType::InMemory(in_memory_store) => in_memory_store.delete(key),
145            KvStoreType::None => Err(KSMRError::StorageError(
146                "No storage available when None is type here".to_string(),
147            )),
148        }
149    }
150
151    fn delete_all(&mut self) -> Result<HashMap<ConfigKeys, String>, KSMRError> {
152        match self {
153            KvStoreType::File(file_store) => file_store.delete_all(),
154            KvStoreType::InMemory(in_memory_store) => in_memory_store.delete_all(),
155            KvStoreType::None => Err(KSMRError::StorageError(
156                "No storage available when None is type here".to_string(),
157            )),
158        }
159    }
160
161    fn contains(&self, key: ConfigKeys) -> Result<bool, KSMRError> {
162        match &self {
163            KvStoreType::File(file_store) => file_store.contains(key),
164            KvStoreType::InMemory(in_memory_store) => in_memory_store.contains(key),
165            KvStoreType::None => Ok(false),
166        }
167    }
168
169    fn create_config_file_if_missing(&self) -> Result<(), KSMRError> {
170        match &self {
171            KvStoreType::File(file_store) => file_store.create_config_file_if_missing(),
172            KvStoreType::InMemory(_) => Ok(()),
173            KvStoreType::None => Err(KSMRError::StorageError(
174                "No storage available when None is type here".to_string(),
175            )),
176        }
177    }
178
179    fn is_empty(&self) -> Result<bool, KSMRError> {
180        match &self {
181            KvStoreType::File(file_store) => file_store.is_empty(),
182            KvStoreType::InMemory(in_memory_store) => in_memory_store.is_empty(),
183            KvStoreType::None => Err(KSMRError::StorageError(
184                "No storage available when None is type here".to_string(),
185            )),
186        }
187    }
188}
189
190pub enum ValueResult {
191    Single(Option<Vec<Value>>),
192    Multiple(Vec<Vec<Value>>),
193}
194
195pub enum StandardFieldTypeEnum {
196    PASSWORD,
197    LOGIN,
198    URL,
199    FILEREF,
200    ONETIMEPASSWORD,
201    NAMES,
202    DATE,
203    BIRTHDATE,
204    EXPIRATIONDATE,
205    TEXT,
206    SECURITYQUESTIONS,
207    MULTILINE,
208    EMAIL,
209    CARDREF,
210    ADDRESSREF,
211    ONETIMECODE,
212    PINCODE,
213    PHONES,
214    SECRET,
215    SECURENOTE,
216    ACCOUNTNUMBER,
217    PAYMENTCARDS,
218    BANKACCOUNT,
219    KEYPAIRS,
220    HOSTS,
221    LICENSENUMBER,
222    RECORDREF,
223    SCHEDULES,
224    DIRECTORYTYPE,
225    DATABASETYPE,
226    PAMHOSTNAME,
227    PAMRESOURCES,
228    CHECKBOX,
229    SCRIPTS,
230    PASSKEYS,
231    ISSSIDHIDDEN,
232    WIFIENCRYPTION,
233    DROPDOWN,
234    RBIURL,
235    APPFILLERS,
236    PAMREMOTEBROWSERSETTINGS,
237    PAMSETTINGS,
238    TRAFFICENCRYPTIONSEED,
239    ADDRESS,
240    NOTE,
241}
242
243impl StandardFieldTypeEnum {
244    pub fn get_type(&self) -> &str {
245        match self {
246            StandardFieldTypeEnum::PASSWORD => "password", // done
247            StandardFieldTypeEnum::LOGIN => "login",       // done
248            StandardFieldTypeEnum::URL => "url",           // done
249            StandardFieldTypeEnum::FILEREF => "fileRef",   // done
250            StandardFieldTypeEnum::ONETIMEPASSWORD => "otp", //done
251            StandardFieldTypeEnum::NAMES => "name",        //done
252            StandardFieldTypeEnum::DATE => "date",         //done
253            StandardFieldTypeEnum::BIRTHDATE => "birthDate", //done
254            StandardFieldTypeEnum::EXPIRATIONDATE => "expirationDate", //done
255            StandardFieldTypeEnum::TEXT => "text",         // done
256            StandardFieldTypeEnum::SECURITYQUESTIONS => "securityQuestion",
257            StandardFieldTypeEnum::MULTILINE => "multiline", //done
258            StandardFieldTypeEnum::EMAIL => "email",         //done
259            StandardFieldTypeEnum::CARDREF => "cardRef",     //done
260            StandardFieldTypeEnum::ADDRESSREF => "addressRef", //done
261            StandardFieldTypeEnum::PINCODE => "pinCode",     // done
262            StandardFieldTypeEnum::PHONES => "phone",        // done
263            StandardFieldTypeEnum::SECRET => "secret",       // done
264            StandardFieldTypeEnum::SECURENOTE => "note",     //done
265            StandardFieldTypeEnum::ACCOUNTNUMBER => "accountNumber", //done
266            StandardFieldTypeEnum::PAYMENTCARDS => "paymentCard", //done
267            StandardFieldTypeEnum::BANKACCOUNT => "bankAccount", //done
268            StandardFieldTypeEnum::KEYPAIRS => "keyPair",    //done
269            StandardFieldTypeEnum::HOSTS => "host",
270            StandardFieldTypeEnum::ADDRESS => "address", //done
271            StandardFieldTypeEnum::LICENSENUMBER => "licenseNumber", //done
272            StandardFieldTypeEnum::RECORDREF => "recordRef",
273            StandardFieldTypeEnum::SCHEDULES => "schedule",
274            StandardFieldTypeEnum::DIRECTORYTYPE => "directoryType",
275            StandardFieldTypeEnum::DATABASETYPE => "databaseType",
276            StandardFieldTypeEnum::PAMHOSTNAME => "pamHostname",
277            StandardFieldTypeEnum::PAMRESOURCES => "pamResources",
278            StandardFieldTypeEnum::CHECKBOX => "checkbox",
279            StandardFieldTypeEnum::SCRIPTS => "script",
280            StandardFieldTypeEnum::PASSKEYS => "passkey",
281            StandardFieldTypeEnum::ISSSIDHIDDEN => "isSSIDHidden",
282            StandardFieldTypeEnum::WIFIENCRYPTION => "wifiEncryption",
283            StandardFieldTypeEnum::DROPDOWN => "dropdown",
284            StandardFieldTypeEnum::RBIURL => "rbiUrl",
285            StandardFieldTypeEnum::APPFILLERS => "appFiller", //done
286            StandardFieldTypeEnum::PAMREMOTEBROWSERSETTINGS => "pamRemoteBrowserSettings",
287            StandardFieldTypeEnum::PAMSETTINGS => "pamSettings",
288            StandardFieldTypeEnum::TRAFFICENCRYPTIONSEED => "trafficEncryptionSeed",
289            StandardFieldTypeEnum::ONETIMECODE => "oneTimeCode",
290            StandardFieldTypeEnum::NOTE => "note", //KEEP-50-SecureNote
291        }
292    }
293}
294
295pub enum DefaultRecordType {
296    Login,
297    SecureNote,
298    BankCard,
299    BankAccounts,
300    DatabaseCredentials,
301    Addresses,
302    BirthCertificate,
303    Contact,
304    DriverLicense,
305    File,
306    HealthInsurance,
307    Membership,
308    Server,
309    IdentityCard,
310    SoftwareLicense,
311    SSHKeys,
312}
313
314impl DefaultRecordType {
315    ///     Login Record recommended fields : StandardFieldTypeEnum::LOGIN, StandardFieldTypeEnum::password
316    ///     SecureNote Records recommended fields : StandardFieldTypeEnum::SECURENOTE
317    ///     
318    pub fn get_type(&self) -> &str {
319        match self {
320            DefaultRecordType::Login => "login",
321            DefaultRecordType::SecureNote => "encryptedNotes",
322            DefaultRecordType::BankCard => "bankCard",
323            DefaultRecordType::BankAccounts => "bankAccount",
324            DefaultRecordType::DatabaseCredentials => "databaseCredentials",
325            DefaultRecordType::Addresses => "address",
326            DefaultRecordType::BirthCertificate => "birthCertificate",
327            DefaultRecordType::Contact => "contact",
328            DefaultRecordType::DriverLicense => "driverLicense",
329            DefaultRecordType::File => "file",
330            DefaultRecordType::SoftwareLicense => "softwareLicense",
331            DefaultRecordType::HealthInsurance => "healthInsurance",
332            DefaultRecordType::Membership => "membership",
333            DefaultRecordType::Server => "serverCredentials",
334            DefaultRecordType::IdentityCard => "ssnCard",
335            DefaultRecordType::SSHKeys => "sshKeys",
336        }
337    }
338}
339
340/// Enum representing all the countries in the world.
341#[derive(Debug, serde::Deserialize, serde::Serialize)]
342pub enum Country {
343    AF, // Afghanistan
344    AL, // Albania
345    DZ, // Algeria
346    AD, // Andorra
347    AO, // Angola
348    AG, // Antigua and Barbuda
349    AR, // Argentina
350    AM, // Armenia
351    AU, // Australia
352    AT, // Austria
353    AZ, // Azerbaijan
354    BS, // Bahamas
355    BH, // Bahrain
356    BD, // Bangladesh
357    BB, // Barbados
358    BY, // Belarus
359    BE, // Belgium
360    BZ, // Belize
361    BJ, // Benin
362    BT, // Bhutan
363    BO, // Bolivia
364    BA, // Bosnia and Herzegovina
365    BW, // Botswana
366    BR, // Brazil
367    BN, // Brunei
368    BG, // Bulgaria
369    BF, // Burkina Faso
370    BI, // Burundi
371    KH, // Cambodia
372    CM, // Cameroon
373    CA, // Canada
374    CV, // Cape Verde
375    CF, // Central African Republic
376    TD, // Chad
377    CL, // Chile
378    CN, // China
379    CO, // Colombia
380    KM, // Comoros
381    CG, // Congo
382    CR, // Costa Rica
383    HR, // Croatia
384    CU, // Cuba
385    CY, // Cyprus
386    CZ, // Czech Republic
387    DK, // Denmark
388    DJ, // Djibouti
389    DM, // Dominica
390    DO, // Dominican Republic
391    TL, // East Timor
392    EC, // Ecuador
393    EG, // Egypt
394    SV, // El Salvador
395    GQ, // Equatorial Guinea
396    ER, // Eritrea
397    EE, // Estonia
398    SZ, // Eswatini
399    ET, // Ethiopia
400    FJ, // Fiji
401    FI, // Finland
402    FR, // France
403    GA, // Gabon
404    GM, // Gambia
405    GE, // Georgia
406    DE, // Germany
407    GH, // Ghana
408    GR, // Greece
409    GD, // Grenada
410    GT, // Guatemala
411    GN, // Guinea
412    GW, // Guinea-Bissau
413    GY, // Guyana
414    HT, // Haiti
415    HN, // Honduras
416    HU, // Hungary
417    IS, // Iceland
418    IN, // India
419    ID, // Indonesia
420    IR, // Iran
421    IQ, // Iraq
422    IE, // Ireland
423    IL, // Israel
424    IT, // Italy
425    CI, // Ivory Coast
426    JM, // Jamaica
427    JP, // Japan
428    JO, // Jordan
429    KZ, // Kazakhstan
430    KE, // Kenya
431    KI, // Kiribati
432    KP, // Korea North
433    KR, // Korea South
434    XK, // Kosovo
435    KW, // Kuwait
436    KG, // Kyrgyzstan
437    LA, // Laos
438    LV, // Latvia
439    LB, // Lebanon
440    LS, // Lesotho
441    LR, // Liberia
442    LY, // Libya
443    LI, // Liechtenstein
444    LT, // Lithuania
445    LU, // Luxembourg
446    MG, // Madagascar
447    MW, // Malawi
448    MY, // Malaysia
449    MV, // Maldives
450    ML, // Mali
451    MT, // Malta
452    MH, // Marshall Islands
453    MR, // Mauritania
454    MU, // Mauritius
455    MX, // Mexico
456    FM, // Micronesia
457    MD, // Moldova
458    MC, // Monaco
459    MN, // Mongolia
460    ME, // Montenegro
461    MA, // Morocco
462    MZ, // Mozambique
463    MM, // Myanmar
464    NA, // Namibia
465    NR, // Nauru
466    NP, // Nepal
467    NL, // Netherlands
468    NZ, // New Zealand
469    NI, // Nicaragua
470    NE, // Niger
471    NG, // Nigeria
472    MK, // North Macedonia
473    NO, // Norway
474    OM, // Oman
475    PK, // Pakistan
476    PW, // Palau
477    PS, // Palestine
478    PA, // Panama
479    PG, // Papua New Guinea
480    PY, // Paraguay
481    PE, // Peru
482    PH, // Philippines
483    PL, // Poland
484    PT, // Portugal
485    QA, // Qatar
486    RO, // Romania
487    RU, // Russia
488    RW, // Rwanda
489    KN, // Saint Kitts and Nevis
490    LC, // Saint Lucia
491    VC, // Saint Vincent and the Grenadines
492    WS, // Samoa
493    SM, // San Marino
494    ST, // Sao Tome and Principe
495    SA, // Saudi Arabia
496    SN, // Senegal
497    RS, // Serbia
498    SC, // Seychelles
499    SL, // Sierra Leone
500    SG, // Singapore
501    SK, // Slovakia
502    SI, // Slovenia
503    SB, // Solomon Islands
504    SO, // Somalia
505    ZA, // South Africa
506    SS, // South Sudan
507    ES, // Spain
508    LK, // Sri Lanka
509    SD, // Sudan
510    SR, // Suriname
511    SE, // Sweden
512    CH, // Switzerland
513    SY, // Syria
514    TW, // Taiwan
515    TJ, // Tajikistan
516    TZ, // Tanzania
517    TH, // Thailand
518    TG, // Togo
519    TO, // Tonga
520    TT, // Trinidad and Tobago
521    TN, // Tunisia
522    TR, // Turkey
523    TM, // Turkmenistan
524    TV, // Tuvalu
525    UG, // Uganda
526    UA, // Ukraine
527    AE, // United Arab Emirates
528    GB, // United Kingdom
529    US, // United States
530    UY, // Uruguay
531    UZ, // Uzbekistan
532    VU, // Vanuatu
533    VA, // Vatican
534    VE, // Venezuela
535    VN, // Vietnam
536    YE, // Yemen
537    ZM, // Zambia
538    ZW, // Zimbabwe
539}
540
541impl Country {
542    /// Converts a string to a `Country` enum variant.
543    pub fn from_string(name: &str) -> Option<Country> {
544        match name.to_lowercase().as_str() {
545            "afghanistan" => Some(Country::AF),
546            "albania" => Some(Country::AL),
547            "algeria" => Some(Country::DZ),
548            "andorra" => Some(Country::AD),
549            "angola" => Some(Country::AO),
550            "antigua and barbuda" => Some(Country::AG),
551            "argentina" => Some(Country::AR),
552            "armenia" => Some(Country::AM),
553            "australia" => Some(Country::AU),
554            "austria" => Some(Country::AT),
555            "azerbaijan" => Some(Country::AZ),
556            "bahamas" => Some(Country::BS),
557            "bahrain" => Some(Country::BH),
558            "bangladesh" => Some(Country::BD),
559            "barbados" => Some(Country::BB),
560            "belarus" => Some(Country::BY),
561            "belgium" => Some(Country::BE),
562            "belize" => Some(Country::BZ),
563            "benin" => Some(Country::BJ),
564            "bhutan" => Some(Country::BT),
565            "bolivia" => Some(Country::BO),
566            "bosnia and herzegovina" => Some(Country::BA),
567            "botswana" => Some(Country::BW),
568            "brazil" => Some(Country::BR),
569            "brunei" => Some(Country::BN),
570            "bulgaria" => Some(Country::BG),
571            "burkina faso" => Some(Country::BF),
572            "burundi" => Some(Country::BI),
573            "cambodia" => Some(Country::KH),
574            "cameroon" => Some(Country::CM),
575            "canada" => Some(Country::CA),
576            "cape verde" => Some(Country::CV),
577            "central african republic" => Some(Country::CF),
578            "chad" => Some(Country::TD),
579            "chile" => Some(Country::CL),
580            "china" => Some(Country::CN),
581            "colombia" => Some(Country::CO),
582            "comoros" => Some(Country::KM),
583            "congo" => Some(Country::CG),
584            "costa rica" => Some(Country::CR),
585            "croatia" => Some(Country::HR),
586            "cuba" => Some(Country::CU),
587            "cyprus" => Some(Country::CY),
588            "czech republic" => Some(Country::CZ),
589            "denmark" => Some(Country::DK),
590            "djibouti" => Some(Country::DJ),
591            "dominica" => Some(Country::DM),
592            "dominican republic" => Some(Country::DO),
593            "east timor" => Some(Country::TL),
594            "ecuador" => Some(Country::EC),
595            "egypt" => Some(Country::EG),
596            "el salvador" => Some(Country::SV),
597            "equatorial guinea" => Some(Country::GQ),
598            "eritrea" => Some(Country::ER),
599            "estonia" => Some(Country::EE),
600            "eswatini" => Some(Country::SZ),
601            "ethiopia" => Some(Country::ET),
602            "fiji" => Some(Country::FJ),
603            "finland" => Some(Country::FI),
604            "france" => Some(Country::FR),
605            "gabon" => Some(Country::GA),
606            "gambia" => Some(Country::GM),
607            "georgia" => Some(Country::GE),
608            "germany" => Some(Country::DE),
609            "ghana" => Some(Country::GH),
610            "greece" => Some(Country::GR),
611            "grenada" => Some(Country::GD),
612            "guatemala" => Some(Country::GT),
613            "guinea" => Some(Country::GN),
614            "guinea bissau" => Some(Country::GW),
615            "guyana" => Some(Country::GY),
616            "haiti" => Some(Country::HT),
617            "honduras" => Some(Country::HN),
618            "hungary" => Some(Country::HU),
619            "iceland" => Some(Country::IS),
620            "india" => Some(Country::IN),
621            "indonesia" => Some(Country::ID),
622            "iran" => Some(Country::IR),
623            "iraq" => Some(Country::IQ),
624            "ireland" => Some(Country::IE),
625            "israel" => Some(Country::IL),
626            "italy" => Some(Country::IT),
627            "ivory coast" => Some(Country::CI),
628            "jamaica" => Some(Country::JM),
629            "japan" => Some(Country::JP),
630            "jordan" => Some(Country::JO),
631            "kazakhstan" => Some(Country::KZ),
632            "kenya" => Some(Country::KE),
633            "kiribati" => Some(Country::KI),
634            "north korea" => Some(Country::KP),
635            "korea north" => Some(Country::KP),
636            "korea south" => Some(Country::KR),
637            "south korea" => Some(Country::KR),
638            "kosovo" => Some(Country::XK),
639            "kuwait" => Some(Country::KW),
640            "kyrgyzstan" => Some(Country::KG),
641            "laos" => Some(Country::LA),
642            "latvia" => Some(Country::LV),
643            "lebanon" => Some(Country::LB),
644            "lesotho" => Some(Country::LS),
645            "liberia" => Some(Country::LR),
646            "libya" => Some(Country::LY),
647            "liechtenstein" => Some(Country::LI),
648            "lithuania" => Some(Country::LT),
649            "luxembourg" => Some(Country::LU),
650            "madagascar" => Some(Country::MG),
651            "malawi" => Some(Country::MW),
652            "malaysia" => Some(Country::MY),
653            "maldives" => Some(Country::MV),
654            "mali" => Some(Country::ML),
655            "malta" => Some(Country::MT),
656            "marshall islands" => Some(Country::MH),
657            "mauritania" => Some(Country::MR),
658            "mauritius" => Some(Country::MU),
659            "mexico" => Some(Country::MX),
660            "micronesia" => Some(Country::FM),
661            "moldova" => Some(Country::MD),
662            "monaco" => Some(Country::MC),
663            "mongolia" => Some(Country::MN),
664            "montenegro" => Some(Country::ME),
665            "morocco" => Some(Country::MA),
666            "mozambique" => Some(Country::MZ),
667            "myanmar" => Some(Country::MM),
668            "namibia" => Some(Country::NA),
669            "nauru" => Some(Country::NR),
670            "nepal" => Some(Country::NP),
671            "netherlands" => Some(Country::NL),
672            "new zealand" => Some(Country::NZ),
673            "nicaragua" => Some(Country::NI),
674            "niger" => Some(Country::NE),
675            "nigeria" => Some(Country::NG),
676            "north macedonia" => Some(Country::MK),
677            "norway" => Some(Country::NO),
678            "oman" => Some(Country::OM),
679            "pakistan" => Some(Country::PK),
680            "palau" => Some(Country::PW),
681            "palestine" => Some(Country::PS),
682            "panama" => Some(Country::PA),
683            "papua new guinea" => Some(Country::PG),
684            "paraguay" => Some(Country::PY),
685            "peru" => Some(Country::PE),
686            "philippines" => Some(Country::PH),
687            "poland" => Some(Country::PL),
688            "portugal" => Some(Country::PT),
689            "qatar" => Some(Country::QA),
690            "romania" => Some(Country::RO),
691            "russia" => Some(Country::RU),
692            "rwanda" => Some(Country::RW),
693            "saint kitts and nevis" => Some(Country::KN),
694            "saint lucia" => Some(Country::LC),
695            "saint vincent and the grenadines" => Some(Country::VC),
696            "samoa" => Some(Country::WS),
697            "san marino" => Some(Country::SM),
698            "sao tome and principe" => Some(Country::ST),
699            "saudi arabia" => Some(Country::SA),
700            "senegal" => Some(Country::SN),
701            "serbia" => Some(Country::RS),
702            "seychelles" => Some(Country::SC),
703            "sierra leone" => Some(Country::SL),
704            "singapore" => Some(Country::SG),
705            "slovakia" => Some(Country::SK),
706            "slovenia" => Some(Country::SI),
707            "solomon islands" => Some(Country::SB),
708            "somalia" => Some(Country::SO),
709            "south africa" => Some(Country::ZA),
710            "south sudan" => Some(Country::SS),
711            "spain" => Some(Country::ES),
712            "sri lanka" => Some(Country::LK),
713            "sudan" => Some(Country::SD),
714            "suriname" => Some(Country::SR),
715            "sweden" => Some(Country::SE),
716            "switzerland" => Some(Country::CH),
717            "syria" => Some(Country::SY),
718            "taiwan" => Some(Country::TW),
719            "tajikistan" => Some(Country::TJ),
720            "tanzania" => Some(Country::TZ),
721            "thailand" => Some(Country::TH),
722            "togo" => Some(Country::TG),
723            "tonga" => Some(Country::TO),
724            "trinidad and tobago" => Some(Country::TT),
725            "tunisia" => Some(Country::TN),
726            "turkey" => Some(Country::TR),
727            "turkmenistan" => Some(Country::TM),
728            "tuvalu" => Some(Country::TV),
729            "uganda" => Some(Country::UG),
730            "ukraine" => Some(Country::UA),
731            "united arab emirates" => Some(Country::AE),
732            "united kingdom" => Some(Country::GB),
733            "united states" => Some(Country::US),
734            "uruguay" => Some(Country::UY),
735            "uzbekistan" => Some(Country::UZ),
736            "vanuatu" => Some(Country::VU),
737            "vatican" => Some(Country::VA),
738            "venezuela" => Some(Country::VE),
739            "vietnam" => Some(Country::VN),
740            "yemen" => Some(Country::YE),
741            "zambia" => Some(Country::ZM),
742            "zimbabwe" => Some(Country::ZW),
743            _ => None,
744        }
745    }
746}
747
748impl fmt::Display for Country {
749    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
750        let country_name = match *self {
751            Country::AF => "Afghanistan",
752            Country::AL => "Albania",
753            Country::DZ => "Algeria",
754            Country::AD => "Andorra",
755            Country::AO => "Angola",
756            Country::AG => "Antigua and Barbuda",
757            Country::AR => "Argentina",
758            Country::AM => "Armenia",
759            Country::AU => "Australia",
760            Country::AT => "Austria",
761            Country::AZ => "Azerbaijan",
762            Country::BS => "Bahamas",
763            Country::BH => "Bahrain",
764            Country::BD => "Bangladesh",
765            Country::BB => "Barbados",
766            Country::BY => "Belarus",
767            Country::BE => "Belgium",
768            Country::BZ => "Belize",
769            Country::BJ => "Benin",
770            Country::BT => "Bhutan",
771            Country::BO => "Bolivia",
772            Country::BA => "Bosnia and Herzegovina",
773            Country::BW => "Botswana",
774            Country::BR => "Brazil",
775            Country::BN => "Brunei",
776            Country::BG => "Bulgaria",
777            Country::BF => "Burkina Faso",
778            Country::BI => "Burundi",
779            Country::KH => "Cambodia",
780            Country::CM => "Cameroon",
781            Country::CA => "Canada",
782            Country::CV => "Cape Verde",
783            Country::CF => "Central African Republic",
784            Country::TD => "Chad",
785            Country::CL => "Chile",
786            Country::CN => "China",
787            Country::CO => "Colombia",
788            Country::KM => "Comoros",
789            Country::CG => "Congo",
790            Country::CR => "Costa Rica",
791            Country::HR => "Croatia",
792            Country::CU => "Cuba",
793            Country::CY => "Cyprus",
794            Country::CZ => "Czech Republic",
795            Country::DK => "Denmark",
796            Country::DJ => "Djibouti",
797            Country::DM => "Dominica",
798            Country::DO => "Dominican Republic",
799            Country::TL => "East Timor",
800            Country::EC => "Ecuador",
801            Country::EG => "Egypt",
802            Country::SV => "El Salvador",
803            Country::GQ => "Equatorial Guinea",
804            Country::ER => "Eritrea",
805            Country::EE => "Estonia",
806            Country::SZ => "Eswatini",
807            Country::ET => "Ethiopia",
808            Country::FJ => "Fiji",
809            Country::FI => "Finland",
810            Country::FR => "France",
811            Country::GA => "Gabon",
812            Country::GM => "Gambia",
813            Country::GE => "Georgia",
814            Country::DE => "Germany",
815            Country::GH => "Ghana",
816            Country::GR => "Greece",
817            Country::GD => "Grenada",
818            Country::GT => "Guatemala",
819            Country::GN => "Guinea",
820            Country::GW => "Guinea Bissau",
821            Country::GY => "Guyana",
822            Country::HT => "Haiti",
823            Country::HN => "Honduras",
824            Country::HU => "Hungary",
825            Country::IS => "Iceland",
826            Country::IN => "India",
827            Country::ID => "Indonesia",
828            Country::IR => "Iran",
829            Country::IQ => "Iraq",
830            Country::IE => "Ireland",
831            Country::IL => "Israel",
832            Country::IT => "Italy",
833            Country::CI => "Ivory Coast",
834            Country::JM => "Jamaica",
835            Country::JP => "Japan",
836            Country::JO => "Jordan",
837            Country::KZ => "Kazakhstan",
838            Country::KE => "Kenya",
839            Country::KI => "Kiribati",
840            Country::KP => "North Korea",
841            Country::KR => "South Korea",
842            Country::XK => "Kosovo",
843            Country::KW => "Kuwait",
844            Country::KG => "Kyrgyzstan",
845            Country::LA => "Laos",
846            Country::LV => "Latvia",
847            Country::LB => "Lebanon",
848            Country::LS => "Lesotho",
849            Country::LR => "Liberia",
850            Country::LY => "Libya",
851            Country::LI => "Liechtenstein",
852            Country::LT => "Lithuania",
853            Country::LU => "Luxembourg",
854            Country::MG => "Madagascar",
855            Country::MW => "Malawi",
856            Country::MY => "Malaysia",
857            Country::MV => "Maldives",
858            Country::ML => "Mali",
859            Country::MT => "Malta",
860            Country::MH => "Marshall Islands",
861            Country::MR => "Mauritania",
862            Country::MU => "Mauritius",
863            Country::MX => "Mexico",
864            Country::FM => "Micronesia",
865            Country::MD => "Moldova",
866            Country::MC => "Monaco",
867            Country::MN => "Mongolia",
868            Country::ME => "Montenegro",
869            Country::MA => "Morocco",
870            Country::MZ => "Mozambique",
871            Country::MM => "Myanmar",
872            Country::NA => "Namibia",
873            Country::NR => "Nauru",
874            Country::NP => "Nepal",
875            Country::NL => "Netherlands",
876            Country::NZ => "New Zealand",
877            Country::NI => "Nicaragua",
878            Country::NE => "Niger",
879            Country::NG => "Nigeria",
880            Country::MK => "North Macedonia",
881            Country::NO => "Norway",
882            Country::OM => "Oman",
883            Country::PK => "Pakistan",
884            Country::PW => "Palau",
885            Country::PS => "Palestine",
886            Country::PA => "Panama",
887            Country::PG => "Papua New Guinea",
888            Country::PY => "Paraguay",
889            Country::PE => "Peru",
890            Country::PH => "Philippines",
891            Country::PL => "Poland",
892            Country::PT => "Portugal",
893            Country::QA => "Qatar",
894            Country::RO => "Romania",
895            Country::RU => "Russia",
896            Country::RW => "Rwanda",
897            Country::KN => "Saint Kitts and Nevis",
898            Country::LC => "Saint Lucia",
899            Country::VC => "Saint Vincent and the Grenadines",
900            Country::WS => "Samoa",
901            Country::SM => "San Marino",
902            Country::ST => "Sao Tome and Principe",
903            Country::SA => "Saudi Arabia",
904            Country::SN => "Senegal",
905            Country::RS => "Serbia",
906            Country::SC => "Seychelles",
907            Country::SL => "Sierra Leone",
908            Country::SG => "Singapore",
909            Country::SK => "Slovakia",
910            Country::SI => "Slovenia",
911            Country::SB => "Solomon Islands",
912            Country::SO => "Somalia",
913            Country::ZA => "South Africa",
914            Country::SS => "South Sudan",
915            Country::ES => "Spain",
916            Country::LK => "Sri Lanka",
917            Country::SD => "Sudan",
918            Country::SR => "Suriname",
919            Country::SE => "Sweden",
920            Country::CH => "Switzerland",
921            Country::SY => "Syria",
922            Country::TW => "Taiwan",
923            Country::TJ => "Tajikistan",
924            Country::TZ => "Tanzania",
925            Country::TH => "Thailand",
926            Country::TG => "Togo",
927            Country::TO => "Tonga",
928            Country::TT => "Trinidad and Tobago",
929            Country::TN => "Tunisia",
930            Country::TR => "Turkey",
931            Country::TM => "Turkmenistan",
932            Country::TV => "Tuvalu",
933            Country::UG => "Uganda",
934            Country::UA => "Ukraine",
935            Country::AE => "United Arab Emirates",
936            Country::GB => "United Kingdom",
937            Country::US => "United States",
938            Country::UY => "Uruguay",
939            Country::UZ => "Uzbekistan",
940            Country::VU => "Vanuatu",
941            Country::VA => "Vatican",
942            Country::VE => "Venezuela",
943            Country::VN => "Vietnam",
944            Country::YE => "Yemen",
945            Country::ZM => "Zambia",
946            Country::ZW => "Zimbabwe",
947        };
948        write!(f, "{}", country_name)
949    }
950}