mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 21:43:18 -07:00
Begin implementing JavaScript Crypto API, add basic Uint8Array methods.
This commit is contained in:
parent
3e8063c2c7
commit
9ed0fadd24
3 changed files with 82 additions and 0 deletions
29
js/crypto.go
Normal file
29
js/crypto.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package js
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
|
||||
"github.com/robertkrimen/otto"
|
||||
)
|
||||
|
||||
func cryptoSha1(call otto.FunctionCall) otto.Value {
|
||||
argv := call.ArgumentList
|
||||
argc := len(argv)
|
||||
if argc != 1 {
|
||||
return ReportError("Crypto.sha1: expected 1 argument, %d given instead.", argc)
|
||||
}
|
||||
|
||||
arg := argv[0]
|
||||
if (!arg.IsString()) {
|
||||
return ReportError("Crypto.sha1: single argument must be a string.")
|
||||
}
|
||||
|
||||
hasher := sha1.New()
|
||||
hasher.Write([]byte(arg.String()))
|
||||
v, err := otto.ToValue(string(hasher.Sum(nil)))
|
||||
if err != nil {
|
||||
return ReportError("Crypto.sha1: could not convert to string: %s", err)
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue