-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42a5764
commit a43d5c8
Showing
6 changed files
with
121 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,20 @@ | ||
use std::io; | ||
|
||
use ed25519::pkcs8::{self, spki}; | ||
use rsa::pkcs8::der; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum Error { | ||
Io(io::Error), | ||
Pkcs8(pkcs8::Error), | ||
Spki(spki::Error), | ||
} | ||
|
||
pub type Result<T> = core::result::Result<T, Error>; | ||
#[error(transparent)] | ||
Io(#[from] io::Error), | ||
|
||
impl From<io::Error> for Error { | ||
fn from(value: io::Error) -> Self { | ||
Self::Io(value) | ||
} | ||
#[error(transparent)] | ||
Pkcs8(#[from] pkcs8::Error), | ||
#[error(transparent)] | ||
Spki(#[from] spki::Error), | ||
#[error(transparent)] | ||
Der(#[from] der::Error), | ||
} | ||
|
||
impl From<pkcs8::Error> for Error { | ||
fn from(value: pkcs8::Error) -> Self { | ||
Self::Pkcs8(value) | ||
} | ||
} | ||
|
||
impl From<spki::Error> for Error { | ||
fn from(value: spki::Error) -> Self { | ||
Self::Spki(value) | ||
} | ||
} | ||
pub type Result<T> = core::result::Result<T, Error>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod error; | ||
pub mod keygen; | ||
mod secret_file; | ||
pub fn add(left: usize, right: usize) -> usize { | ||
left + right | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// use crate::error::Result; | ||
use std::io::Result; | ||
use std::path::Path; | ||
|
||
#[cfg(unix)] | ||
pub(crate) async fn write_secret_file(path: impl AsRef<Path>, data: &[u8]) -> Result<()> { | ||
use tokio::{fs, io::AsyncWriteExt}; | ||
|
||
/// File permissions for secret data | ||
#[cfg(unix)] | ||
const SECRET_FILE_PERMS: u32 = 0o600; | ||
|
||
let mut file = fs::OpenOptions::new() | ||
.create(true) | ||
.write(true) | ||
.truncate(true) | ||
.mode(SECRET_FILE_PERMS) | ||
.open(path) | ||
.await?; | ||
file.write_all(data).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(not(unix))] | ||
pub(crate) async fn write_secret_file(path: impl AsRef<Path>, data: &[u8]) -> Result<()> { | ||
use tokio::fs; | ||
|
||
fs::write(path, data).await?; | ||
Ok(()) | ||
} |