| 12 | } |
| 13 | |
| 14 | func (b *Base64) Call(args []super.Value) super.Value { |
| 15 | val := args[0].Under() |
| 16 | if val.IsNull() { |
| 17 | return super.Null |
| 18 | } |
| 19 | switch val.Type().ID() { |
| 20 | case super.IDBytes: |
| 21 | return super.NewString(base64.StdEncoding.EncodeToString(val.Bytes())) |
| 22 | case super.IDString: |
| 23 | bytes, err := base64.StdEncoding.DecodeString(super.DecodeString(val.Bytes())) |
| 24 | if err != nil { |
| 25 | return b.sctx.WrapError("base64: string argument is not base64", val) |
| 26 | } |
| 27 | return super.NewBytes(bytes) |
| 28 | default: |
| 29 | return b.sctx.WrapError("base64: argument must a bytes or string type", val) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | type Hex struct { |
| 34 | sctx *super.Context |