Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ go_library(
"//internal/parser:go_default_library",
"//internal/program:go_default_library",
"@io_k8s_sigs_yaml//:go_default_library",
"@org_golang_x_crypto//sha3:go_default_library",
],
)

Expand Down
8 changes: 7 additions & 1 deletion ast/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
Expand All @@ -13,3 +13,9 @@ go_library(
importpath = "github.com/google/go-jsonnet/ast",
visibility = ["//visibility:public"],
)

go_test(
name = "go_default_test",
srcs = ["util_test.go"],
embed = [":go_default_library"],
)
35 changes: 30 additions & 5 deletions bazel/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def jsonnet_go_dependencies(go_sdk_version = "host"):
)
go_repository(
name = "com_github_fatih_color",
build_external = "external",
importpath = "github.com/fatih/color",
sum = "h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc=",
version = "v1.12.0",
build_external = "external",
)

go_repository(
Expand All @@ -47,17 +47,17 @@ def jsonnet_go_dependencies(go_sdk_version = "host"):
)
go_repository(
name = "com_github_mattn_go_colorable",
build_external = "external",
importpath = "github.com/mattn/go-colorable",
sum = "h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=",
version = "v0.1.8",
build_external = "external",
)
go_repository(
name = "com_github_mattn_go_isatty",
build_external = "external",
importpath = "github.com/mattn/go-isatty",
sum = "h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=",
version = "v0.0.12",
build_external = "external",
)
go_repository(
name = "com_github_pmezard_go_difflib",
Expand Down Expand Up @@ -101,9 +101,34 @@ def jsonnet_go_dependencies(go_sdk_version = "host"):
sum = "h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=",
version = "v1.1.0",
)
go_repository(
name = "org_golang_x_crypto",
importpath = "golang.org/x/crypto",
sum = "h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=",
version = "v0.9.0",
)
go_repository(
name = "org_golang_x_net",
importpath = "golang.org/x/net",
sum = "h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=",
version = "v0.10.0",
)

go_repository(
name = "org_golang_x_sys",
importpath = "golang.org/x/sys",
sum = "h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=",
version = "v0.1.0",
sum = "h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=",
version = "v0.8.0",
)
go_repository(
name = "org_golang_x_term",
importpath = "golang.org/x/term",
sum = "h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols=",
version = "v0.8.0",
)
go_repository(
name = "org_golang_x_text",
importpath = "golang.org/x/text",
sum = "h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=",
version = "v0.9.0",
)
44 changes: 44 additions & 0 deletions builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package jsonnet
import (
"bytes"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"encoding/base64"
"encoding/hex"
"encoding/json"
Expand All @@ -31,6 +34,7 @@ import (
"strings"

"github.com/google/go-jsonnet/ast"
"golang.org/x/crypto/sha3"
)

func builtinPlus(i *interpreter, x, y value) (value, error) {
Expand Down Expand Up @@ -916,6 +920,42 @@ func builtinMd5(i *interpreter, x value) (value, error) {
return makeValueString(hex.EncodeToString(hash[:])), nil
}

func builtinSha1(i *interpreter, x value) (value, error) {
str, err := i.getString(x)
if err != nil {
return nil, err
}
hash := sha1.Sum([]byte(str.getGoString()))
return makeValueString(hex.EncodeToString(hash[:])), nil
}

func builtinSha256(i *interpreter, x value) (value, error) {
str, err := i.getString(x)
if err != nil {
return nil, err
}
hash := sha256.Sum256([]byte(str.getGoString()))
return makeValueString(hex.EncodeToString(hash[:])), nil
}

func builtinSha512(i *interpreter, x value) (value, error) {
str, err := i.getString(x)
if err != nil {
return nil, err
}
hash := sha512.Sum512([]byte(str.getGoString()))
return makeValueString(hex.EncodeToString(hash[:])), nil
}

func builtinSha3(i *interpreter, x value) (value, error) {
str, err := i.getString(x)
if err != nil {
return nil, err
}
hash := sha3.Sum512([]byte(str.getGoString()))
return makeValueString(hex.EncodeToString(hash[:])), nil
}

func builtinBase64(i *interpreter, input value) (value, error) {
var byteArr []byte

Expand Down Expand Up @@ -2276,6 +2316,10 @@ var funcBuiltins = buildBuiltinMap([]builtin{
&binaryBuiltin{name: "pow", function: builtinPow, params: ast.Identifiers{"x", "n"}},
&binaryBuiltin{name: "modulo", function: builtinModulo, params: ast.Identifiers{"x", "y"}},
&unaryBuiltin{name: "md5", function: builtinMd5, params: ast.Identifiers{"s"}},
&unaryBuiltin{name: "sha1", function: builtinSha1, params: ast.Identifiers{"s"}},
&unaryBuiltin{name: "sha256", function: builtinSha256, params: ast.Identifiers{"s"}},
&unaryBuiltin{name: "sha512", function: builtinSha512, params: ast.Identifiers{"s"}},
&unaryBuiltin{name: "sha3", function: builtinSha3, params: ast.Identifiers{"s"}},
&binaryBuiltin{name: "xnor", function: builtinXnor, params: ast.Identifiers{"x", "y"}},
&binaryBuiltin{name: "xor", function: builtinXor, params: ast.Identifiers{"x", "y"}},
&binaryBuiltin{name: "lstripChars", function: builtinLstripChars, params: ast.Identifiers{"str", "chars"}},
Expand Down
2 changes: 1 addition & 1 deletion c-bindings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ go_library(
],
cgo = True,
copts = ["-Wall -Icpp-jsonnet/include"], # keep
cxxopts = ["-std=c++11"],
cxxopts = ["-std=c++11 -Wall -Icpp-jsonnet/include"],
importpath = "github.com/google/go-jsonnet/c-bindings",
visibility = ["//visibility:private"],
deps = [
Expand Down
15 changes: 8 additions & 7 deletions cmd/wasm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
name = "go_default_library",
srcs = [
"main.go",
],
srcs = ["main.go"],
importpath = "github.com/google/go-jsonnet/cmd/wasm",
visibility = ["//visibility:private"],
deps = [
"//:go_default_library",
"//internal/formatter:go_default_library",
],
deps = select({
"@io_bazel_rules_go//go/platform:js_wasm": [
"//:go_default_library",
"//internal/formatter:go_default_library",
],
"//conditions:default": [],
}),
)

go_binary(
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
require (
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/sys v0.8.0 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNX
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
4 changes: 4 additions & 0 deletions linter/internal/types/stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ func prepareStdlib(g *typeGraph) {
"base64DecodeBytes": g.newSimpleFuncType(numberType, "str"),
"base64Decode": g.newSimpleFuncType(stringType, "str"),
"md5": g.newSimpleFuncType(stringType, "s"),
"sha1": g.newSimpleFuncType(stringType, "s"),
"sha256": g.newSimpleFuncType(stringType, "s"),
"sha512": g.newSimpleFuncType(stringType, "s"),
"sha3": g.newSimpleFuncType(stringType, "s"),

// JSON Merge Patch

Expand Down
1 change: 1 addition & 0 deletions testdata/builtinSha1.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"
1 change: 1 addition & 0 deletions testdata/builtinSha1.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std.sha1("foo")
Empty file.
1 change: 1 addition & 0 deletions testdata/builtinSha256.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"
1 change: 1 addition & 0 deletions testdata/builtinSha256.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std.sha256("foo")
Empty file.
1 change: 1 addition & 0 deletions testdata/builtinSha3.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"4bca2b137edc580fe50a88983ef860ebaca36c857b1f492839d6d7392452a63c82cbebc68e3b70a2a1480b4bb5d437a7cba6ecf9d89f9ff3ccd14cd6146ea7e7"
1 change: 1 addition & 0 deletions testdata/builtinSha3.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std.sha3("foo")
Empty file.
1 change: 1 addition & 0 deletions testdata/builtinSha512.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7"
1 change: 1 addition & 0 deletions testdata/builtinSha512.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std.sha512("foo")
Empty file.