Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
tabVersion committed Jan 22, 2024
1 parent 84cb291 commit e901dd2
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
104 changes: 104 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/expr/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ ignored = ["workspace-hack", "ctor"]
normal = ["workspace-hack", "ctor"]

[dependencies]
aes-gcm = { version = "0.10.3", features = ["aes",
"alloc",
"getrandom"
] }
aho-corasick = "1"
anyhow = "1"
arrow-schema = { workspace = true }
Expand Down
32 changes: 32 additions & 0 deletions src/expr/impl/src/scalar/encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,35 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use aes_gcm::{Aes128Gcm, Aes256Gcm, Key, KeyInit, OsRng};
use risingwave_expr::{function, ExprError, Result};

enum CypherEnum {
Aes128(Aes128Gcm),
Aes256(Aes256Gcm),
}

fn build_encrypt(key: &[u8], mode: &str) -> Result<CypherEnum> {
let cypher = match mode.to_lowercase().as_str() {
"aes128" => CypherEnum::Aes128(Aes128Gcm::new(Key::<Aes128Gcm>::from_slice(key))),
"aes256" => CypherEnum::Aes256(Aes256Gcm::new(Key::<Aes256Gcm>::from_slice(key))),
_ => {
return Err(ExprError::InvalidParam {
name: "mode",
reason: format!("invalid mode: {}, only accept aes128 or aes256 here", mode).into(),
});
}
};

Ok(cypher)
}

/// from pg doc https://www.postgresql.org/docs/current/pgcrypto.html#PGCRYPTO-RAW-ENC-FUNCS
#[function(
"decrypt(bytea, bytea, text) -> bytea",
prebuilt = "build_encrypt($1, $2)"
)]
pub fn decrypt(data: &[u8], cypher: CypherEnum) -> Result<Vec<u8>> {
Ok(data)
}
2 changes: 2 additions & 0 deletions src/workspace-hack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ combine = { version = "4", features = ["tokio"] }
crossbeam-epoch = { version = "0.9" }
crossbeam-utils = { version = "0.8" }
crypto-bigint = { version = "0.5", features = ["generic-array", "zeroize"] }
crypto-common = { version = "0.1", default-features = false, features = ["getrandom", "std"] }
deranged = { version = "0.3", default-features = false, features = ["powerfmt", "serde", "std"] }
digest = { version = "0.10", features = ["mac", "oid", "std"] }
either = { version = "1", features = ["serde"] }
Expand Down Expand Up @@ -162,6 +163,7 @@ auto_enums = { version = "0.8", features = ["futures03", "tokio1"] }
bitflags = { version = "2", default-features = false, features = ["serde", "std"] }
bytes = { version = "1", features = ["serde"] }
cc = { version = "1", default-features = false, features = ["parallel"] }
crypto-common = { version = "0.1", default-features = false, features = ["getrandom", "std"] }
deranged = { version = "0.3", default-features = false, features = ["powerfmt", "serde", "std"] }
digest = { version = "0.10", features = ["mac", "oid", "std"] }
either = { version = "1", features = ["serde"] }
Expand Down

0 comments on commit e901dd2

Please sign in to comment.