-
Notifications
You must be signed in to change notification settings - Fork 2
add salt function #39
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -186,3 +186,22 @@ func encodeB64DecodeEval(ctx expr.EvalContext, args []value.Value) (value.Value, | |||
| } | ||||
| return value.NewStringValue(string(by)), true | ||||
| } | ||||
|
|
||||
| // RandomSalt generates a random ten-digit number as a string | ||||
| // | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to register your function as well here: qlbridge/expr/builtins/builtins.go Line 127 in 85f4541
something like: |
||||
| // random_salt() => "1234567890" | ||||
| type RandomSalt struct{} | ||||
|
|
||||
| // Type string | ||||
| func (m *RandomSalt) Type() value.ValueType { return value.StringType } | ||||
| func (m *RandomSalt) Validate(n *expr.FuncNode) (expr.EvaluatorFunc, error) { | ||||
| if len(n.Args) != 0 { | ||||
| return nil, fmt.Errorf("Expected 0 args for random_salt() but got %s", n) | ||||
| } | ||||
| return randomSaltEval, nil | ||||
| } | ||||
| func randomSaltEval(ctx expr.EvalContext, args []value.Value) (value.Value, bool) { | ||||
| // Generate a random number between 1000000000 and 9999999999 | ||||
| randomNum := rand.Int63n(9000000000) + 1000000000 | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want to use the crypto rand here? I think we need to fix the imports for the file too... import "crypto/rand"
...
salt := make([]byte, 10)
if ib, err := rand.Read(salt); err != nil && ib != len(salt) {
return value.EmptyStringValue, false
}
return value.NewStringValue(base64.URLEncoding.EncodeToString(salt)), true |
||||
| return value.NewStringValue(fmt.Sprintf("%d", randomNum)), true | ||||
| } | ||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im going to talk this one over with the team tomorrow. If the goal here is to have this generate a random salt, that is only set once and never changed. We may need to write this as one of our internal built-ins, so it has context from the entire entity. Otherwise each time the profile is evaluated it's salt will change, which will change it's hashed email address.