enprot/policy/
default.rs

1// Copyright (c) 2019-2020 [Ribose Inc](https://www.ribose.com).
2//
3// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions
5// are met:
6// 1. Redistributions of source code must retain the above copyright
7//    notice, this list of conditions and the following disclaimer.
8// 2. Redistributions in binary form must reproduce the above copyright
9//    notice, this list of conditions and the following disclaimer in the
10//    documentation and/or other materials provided with the distribution.
11//
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13// ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
24use std::collections::BTreeMap;
25
26use policy::CryptoPolicy;
27
28pub struct CryptoPolicyDefault {}
29
30impl CryptoPolicyDefault {
31    const DEFAULT_PBKDF_ALG: &'static str = "argon2";
32    const DEFAULT_PBKDF_SALT_LEN: usize = 16;
33    pub const DEFAULT_PBKDF_MSEC: u32 = 100;
34    const DEFAULT_CIPHER_ALG: &'static str = "aes-256-siv";
35}
36
37// allow everything
38impl CryptoPolicy for CryptoPolicyDefault {
39    fn check_hash(&self, _alg: &str) -> Result<(), &'static str> {
40        Ok(())
41    }
42
43    fn check_pbkdf(
44        &self,
45        _alg: &str,
46        _key_len: usize,
47        _password: &str,
48        _salt: &[u8],
49        _params: &BTreeMap<String, usize>,
50    ) -> Result<(), &'static str> {
51        Ok(())
52    }
53
54    fn check_cipher(
55        &self,
56        _alg: &str,
57        _key: &[u8],
58        _iv: &[u8],
59        _ad: &[u8],
60    ) -> Result<(), &'static str> {
61        Ok(())
62    }
63
64    fn default_pbkdf_alg(&self) -> String {
65        Self::DEFAULT_PBKDF_ALG.to_string()
66    }
67
68    fn default_pbkdf_salt_length(&self) -> usize {
69        Self::DEFAULT_PBKDF_SALT_LEN
70    }
71
72    fn default_pbkdf_millis(&self) -> u32 {
73        Self::DEFAULT_PBKDF_MSEC
74    }
75
76    fn default_cipher_alg(&self) -> String {
77        Self::DEFAULT_CIPHER_ALG.to_string()
78    }
79}