credence_lib/configuration/port/
key.rs1use super::{super::error::*, loadable_bytes::*};
2
3use {bytes::*, compris::resolve::*, kutil_cli::debug::*, std::path::*};
4
5#[derive(Clone, Debug, Debuggable, Default, Resolve)]
11pub struct Key {
12 #[resolve(required)]
14 #[debuggable(as(display), style(symbol))]
15 pub certificates: LoadableBytes,
16
17 #[resolve(required, key = "private-key")]
19 #[debuggable(as(display), style(symbol))]
20 pub private_key: LoadableBytes,
21}
22
23impl Key {
24 pub fn validate<PathT>(&mut self, base_path: PathT) -> Result<(), ConfigurationError>
26 where
27 PathT: AsRef<Path>,
28 {
29 if let LoadableBytes::Path(path) = &mut self.certificates {
30 if !path.is_absolute() {
31 *path = base_path.as_ref().join(&path);
32 }
33 }
34
35 if let LoadableBytes::Path(path) = &mut self.private_key {
36 if !path.is_absolute() {
37 *path = base_path.as_ref().join(&path);
38 }
39 }
40
41 Ok(())
42 }
43
44 pub fn to_bytes(&self) -> Result<(Bytes, Bytes), ConfigurationError> {
46 Ok((self.certificates.to_bytes()?, self.private_key.to_bytes()?))
47 }
48}