mirror of
https://github.com/NLnetLabs/krill.git
synced 2026-09-23 09:54:55 +02:00
Clean up potentially unsafe unwrap() statements.
This commit is contained in:
@@ -11,7 +11,6 @@ use serde::de;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
use rpki::cert::Cert;
|
||||
use rpki::crypto::Signer;
|
||||
use rpki::uri;
|
||||
use rpki::x509::Time;
|
||||
|
||||
@@ -53,11 +52,14 @@ impl TryFrom<&PathBuf> for Handle {
|
||||
type Error = InvalidHandle;
|
||||
|
||||
fn try_from(path: &PathBuf) -> Result<Self, Self::Error> {
|
||||
let path = path.file_name().unwrap();
|
||||
let s = path.to_string_lossy().to_string();
|
||||
let s = s.replace("+", "/");
|
||||
let s = s.replace("=", "\\");
|
||||
Self::from_str(&s)
|
||||
if let Some(path) = path.file_name() {
|
||||
let s = path.to_string_lossy().to_string();
|
||||
let s = s.replace("+", "/");
|
||||
let s = s.replace("=", "\\");
|
||||
Self::from_str(&s)
|
||||
} else {
|
||||
Err(InvalidHandle)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,15 +131,6 @@ pub struct InvalidHandle;
|
||||
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct Token(String);
|
||||
|
||||
impl Token {
|
||||
pub fn random<S: Signer>(signer: &S) -> Self {
|
||||
let mut res = <[u8; 20]>::default();
|
||||
signer.rand(&mut res).unwrap();
|
||||
let string = hex::encode(res);
|
||||
Token(string)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for Token {
|
||||
fn from(s: &str) -> Self {
|
||||
Token(s.to_string())
|
||||
|
||||
@@ -375,10 +375,12 @@ impl KeyStore for DiskKeyStore {
|
||||
|
||||
if let Ok(dir) = fs::read_dir(&self.dir) {
|
||||
for d in dir {
|
||||
let path = d.unwrap().path();
|
||||
if path.is_dir() {
|
||||
if let Ok(id) = Handle::try_from(&path) {
|
||||
res.push(id);
|
||||
if let Ok(d) = d {
|
||||
let path = d.path();
|
||||
if path.is_dir() {
|
||||
if let Ok(id) = Handle::try_from(&path) {
|
||||
res.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ pub struct Message {
|
||||
/// # Data Access
|
||||
///
|
||||
impl Message {
|
||||
pub fn unwrap(self) -> (Sender, Recipient, Content) {
|
||||
pub fn unpack(self) -> (Sender, Recipient, Content) {
|
||||
(self.sender, self.recipient, self.content)
|
||||
}
|
||||
|
||||
|
||||
@@ -329,7 +329,7 @@ impl<S: Signer> CaServer<S> {
|
||||
|
||||
let content = ca.verify_rfc6492(msg)?;
|
||||
|
||||
let (child, recipient, content) = content.unwrap();
|
||||
let (child, recipient, content) = content.unpack();
|
||||
|
||||
let cms_logger = CmsLogger::for_rfc6492_rcvd(self.rfc6492_log_dir.as_ref(), &recipient, &child);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user