@@ -21,7 +21,6 @@ import (
2121 "fmt"
2222 "hash"
2323 "io"
24- "strconv"
2524 "strings"
2625)
2726
@@ -49,30 +48,24 @@ func NewHash(s string) (Hash, error) {
4948}
5049
5150// MarshalJSON implements json.Marshaler
52- func (h Hash ) MarshalJSON () ([]byte , error ) {
53- return json .Marshal (h .String ())
54- }
51+ func (h Hash ) MarshalJSON () ([]byte , error ) { return json .Marshal (h .String ()) }
5552
5653// UnmarshalJSON implements json.Unmarshaler
5754func (h * Hash ) UnmarshalJSON (data []byte ) error {
58- s , err := strconv . Unquote ( string ( data ))
59- if err != nil {
55+ var s string
56+ if err := json . Unmarshal ( data , & s ); err != nil {
6057 return err
6158 }
6259 return h .parse (s )
6360}
6461
6562// MarshalText implements encoding.TextMarshaler. This is required to use
6663// v1.Hash as a key in a map when marshalling JSON.
67- func (h Hash ) MarshalText () (text []byte , err error ) {
68- return []byte (h .String ()), nil
69- }
64+ func (h Hash ) MarshalText () ([]byte , error ) { return []byte (h .String ()), nil }
7065
7166// UnmarshalText implements encoding.TextUnmarshaler. This is required to use
7267// v1.Hash as a key in a map when unmarshalling JSON.
73- func (h * Hash ) UnmarshalText (text []byte ) error {
74- return h .parse (string (text ))
75- }
68+ func (h * Hash ) UnmarshalText (text []byte ) error { return h .parse (string (text )) }
7669
7770// Hasher returns a hash.Hash for the named algorithm (e.g. "sha256")
7871func Hasher (name string ) (hash.Hash , error ) {
0 commit comments