tugger_windows_codesign/
lib.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5/*! Code signing on Windows. */
6
7mod signing;
8pub use signing::*;
9mod signtool;
10pub use signtool::*;
11
12/// Defines a specific Windows certificate system store.
13///
14/// See https://docs.microsoft.com/en-us/windows/win32/seccrypto/system-store-locations
15/// for meanings.
16#[derive(Clone, Copy, Debug)]
17pub enum SystemStore {
18    My,
19    Root,
20    Trust,
21    Ca,
22    UserDs,
23}
24
25impl Default for SystemStore {
26    fn default() -> Self {
27        Self::My
28    }
29}
30
31impl AsRef<str> for SystemStore {
32    fn as_ref(&self) -> &str {
33        match self {
34            Self::My => "MY",
35            Self::Root => "Root",
36            Self::Trust => "Trust",
37            Self::Ca => "CA",
38            Self::UserDs => "UserDS",
39        }
40    }
41}
42
43impl TryFrom<&str> for SystemStore {
44    type Error = String;
45
46    fn try_from(value: &str) -> Result<Self, Self::Error> {
47        match value.to_lowercase().as_str() {
48            "my" => Ok(Self::My),
49            "root" => Ok(Self::Root),
50            "trust" => Ok(Self::Trust),
51            "ca" => Ok(Self::Ca),
52            "userds" => Ok(Self::UserDs),
53            _ => Err(format!("{} is not a valid system store value", value)),
54        }
55    }
56}