Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rhai sha256 hashing function #4939

Closed
smyrick opened this issue Apr 10, 2024 · 1 comment · Fixed by #4940
Closed

Add Rhai sha256 hashing function #4939

smyrick opened this issue Apr 10, 2024 · 1 comment · Fixed by #4940

Comments

@smyrick
Copy link
Member

smyrick commented Apr 10, 2024

Is your feature request related to a problem? Please describe.**

We want to hash error codes and custom values in the request/response for logging purposes. SHA256 is also used with Persisted Queries and caching so being able to generate the same values in Rhai could help with custom scripting

Base64 encoding doesn't help because anyone who has access to the encoded messages can easily decode them vs sha256 hashing which is one way

Describe the solution you'd like**

Expose new global functions in rhai, similar to base64::*, but for sha256

let text = "alice and bob";
let hash = sha256::digest(text);

print(hash) # 629f44ee052437b149370d37b9810e19a1df618712ccae63593d37c9b96e3237

Describe alternatives you've considered**

We could use a coprocessor to solve this today

Additional context**

This was brought up in a larger issue as one step to support encryption in Rhai in #2025 but that issue was closed because we added native Sigv4 support. This issue was also opened just for the sha256 function, but it was closed as a duplicate of the larger crypto issue: #2112

Outside of crypto support it would be helpful to have a sha256 hashing function available so we don't have to use a coprocessor for small request/response manipulation

@elloboblanco
Copy link

throwing in my support for this, would love this feature 🙌🏻

garypen pushed a commit that referenced this issue Apr 16, 2024
This adds a new `sha256::digest` function to Rhai to enable hash values.

Fixes #4939 

<!-- start metadata -->
---

**Checklist**

Complete the checklist (and note appropriate exceptions) before the PR
is marked ready-for-review.

- [x] Changes are compatible[^1]
- [x] Documentation[^2] completed
- [ ] Performance impact assessed and acceptable
- Tests added and passing[^3]
    - [x] Unit Tests
    - [ ] Integration Tests
    - [ ] Manual Tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants