mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
fix!: Remove sha1 dependency (#379)
Removed cryptographically insecure sha1. This existed only for OPA compatibility. Also exclude bindings from main workspace Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
c6a5f1d852
commit
4a2df93ae2
@@ -11,18 +11,15 @@ use anyhow::{bail, Result};
|
||||
use constant_time_eq::constant_time_eq;
|
||||
use hmac::{Hmac, Mac};
|
||||
use md5::{Digest, Md5};
|
||||
use sha1::Sha1;
|
||||
use sha2::{Sha256, Sha512};
|
||||
|
||||
pub fn register(m: &mut builtins::BuiltinsMap<&'static str, builtins::BuiltinFcn>) {
|
||||
m.insert("crypto.hmac.equal", (hmac_equal_fixed_time, 2));
|
||||
m.insert("crypto.hmac.md5", (hmac_md5, 2));
|
||||
m.insert("crypto.hmac.sha1", (hmac_sha1, 2));
|
||||
m.insert("crypto.hmac.sha256", (hmac_sha256, 2));
|
||||
m.insert("crypto.hmac.sha512", (hmac_sha512, 2));
|
||||
|
||||
m.insert("crypto.md5", (crypto_md5, 1));
|
||||
m.insert("crypto.sha1", (crypto_sha1, 1));
|
||||
m.insert("crypto.sha256", (crypto_sha256, 1));
|
||||
}
|
||||
|
||||
@@ -60,22 +57,6 @@ fn hmac_md5(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool) ->
|
||||
Ok(Value::String(hex::encode(result.into_bytes()).into()))
|
||||
}
|
||||
|
||||
fn hmac_sha1(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool) -> Result<Value> {
|
||||
let name = "crypto.hmac.sha1";
|
||||
ensure_args_count(span, name, params, args, 2)?;
|
||||
|
||||
let x = ensure_string(name, ¶ms[0], &args[0])?;
|
||||
let key = ensure_string(name, ¶ms[1], &args[1])?;
|
||||
|
||||
let mut hmac = Hmac::<Sha1>::new_from_slice(key.as_bytes())
|
||||
.or_else(|_| bail!(span.error("failed to create hmac instance")))?;
|
||||
|
||||
hmac.update(x.as_bytes());
|
||||
let result = hmac.finalize();
|
||||
|
||||
Ok(Value::String(hex::encode(result.into_bytes()).into()))
|
||||
}
|
||||
|
||||
fn hmac_sha256(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool) -> Result<Value> {
|
||||
let name = "crypto.hmac.sha256";
|
||||
ensure_args_count(span, name, params, args, 2)?;
|
||||
@@ -122,20 +103,6 @@ fn crypto_md5(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool)
|
||||
Ok(Value::String(hex::encode(result).into()))
|
||||
}
|
||||
|
||||
fn crypto_sha1(span: &Span, params: &[Ref<Expr>], args: &[Value], _strict: bool) -> Result<Value> {
|
||||
let name = "crypto.sha1";
|
||||
ensure_args_count(span, name, params, args, 1)?;
|
||||
|
||||
let x = ensure_string(name, ¶ms[0], &args[0])?;
|
||||
|
||||
let mut h = Sha1::new();
|
||||
|
||||
h.update(x.as_bytes());
|
||||
let result = h.finalize();
|
||||
|
||||
Ok(Value::String(hex::encode(result).into()))
|
||||
}
|
||||
|
||||
fn crypto_sha256(
|
||||
span: &Span,
|
||||
params: &[Ref<Expr>],
|
||||
|
||||
Reference in New Issue
Block a user