Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1b13a1

Browse files
committed
remove encrypt and decrypt and format
1 parent203bf72 commita1b13a1

File tree

2 files changed

+0
-80
lines changed

2 files changed

+0
-80
lines changed

‎pgml-dashboard/src/utils/config.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ pub fn static_dir() -> String {
3939
// }
4040
// }
4141

42-
43-
4442
pubfnsearch_index_dir() ->String{
4543
matchvar("SEARCH_INDEX_DIRECTORY"){
4644
Ok(path) => path,

‎pgml-dashboard/src/utils/secure.rs‎

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
use aes_gcm::{
2-
aead::Aead,
3-
Aes256Gcm,
4-
KeyInit,
5-
Nonce,// Or `Aes128Gcm`
6-
};
7-
use anyhow::anyhow;
8-
use base64::{engine::general_purpose,Engineas _};
91
use rand::{distributions::Alphanumeric,Rng};
102
use serde::{Deserialize,Serialize};
11-
use sqlx::postgres::types::PgInterval;
12-
use time::Duration;
133

144
/// Encrypted value that can be stored safely in
155
/// any storage medium, including a database.
@@ -27,71 +17,3 @@ pub fn random_string(len: usize) -> String {
2717
.map(char::from)
2818
.collect()
2919
}
30-
31-
/// Encrypt a value using a AES-256-GCM.
32-
///
33-
/// The provided key must be 256-bits, or 32 characters long.
34-
pubfnencrypt(key:&str,value:&str) -> anyhow::Result<String>{
35-
let nonce = rand::thread_rng().gen::<[u8;12]>();
36-
let key = general_purpose::STANDARD
37-
.decode(key)
38-
.expect("base64 decode failed on key");
39-
40-
let cipher =matchAes256Gcm::new_from_slice(&key){
41-
Ok(cipher) => cipher,
42-
Err(err) =>returnErr(anyhow::anyhow!("key error: {:?}", err)),
43-
};
44-
45-
let nonce =Nonce::from_slice(&nonce);
46-
let encrypted =match cipher.encrypt(&nonce, value.as_bytes()){
47-
Ok(encrypted) => encrypted,
48-
Err(err) =>returnErr(anyhow::anyhow!("encryption error: {:?}", err)),
49-
};
50-
51-
Ok(serde_json::to_string(&EncryptedValue{
52-
value: encrypted,
53-
nonce: nonce.to_vec(),
54-
})?)
55-
}
56-
57-
/// Take care of unusual error casting that is required.
58-
pubfnpg_duration(dur:&Duration) -> anyhow::Result<PgInterval>{
59-
PgInterval::try_from(dur.clone()).map_err(|err|anyhow!(err))
60-
}
61-
62-
/// Decrypt a value using AES-256-GCM.
63-
///
64-
/// The provided key must be 256-bits, or 32 characters long.
65-
pubfndecrypt(key:&str,value:&str) -> anyhow::Result<String>{
66-
let value:EncryptedValue = serde_json::from_str(value)?;
67-
let key = general_purpose::STANDARD
68-
.decode(key)
69-
.expect("base64 decode failed on key");
70-
71-
let cipher =matchAes256Gcm::new_from_slice(&key){
72-
Ok(cipher) => cipher,
73-
Err(err) =>returnErr(anyhow::anyhow!("key error: {:?}", err)),
74-
};
75-
76-
let nonce =Nonce::from_slice(&value.nonce);
77-
let decrpyted =match cipher.decrypt(&nonce, value.value.as_slice()){
78-
Ok(value) => value,
79-
Err(err) =>returnErr(anyhow::anyhow!("decryption error: {:?}", err)),
80-
};
81-
82-
Ok(String::from_utf8(decrpyted)?)
83-
}
84-
85-
#[cfg(test)]
86-
mod test{
87-
usesuper::*;
88-
89-
#[test]
90-
fntest_encrypt(){
91-
let key ="CED3lXZ4voSifPakjydU9cUxgD5xYTrkJUpqvX1RBUA=";
92-
let enc =encrypt(key,"test value").unwrap();
93-
let dec =decrypt(key,&enc).unwrap();
94-
95-
assert_eq!(dec.as_str(),"test value");
96-
}
97-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp