MCPcopy
hub / github.com/kashav/fsql / cmpHash

Function cmpHash

evaluate/compare.go:126–150  ·  view source on GitHub ↗

cmpHash computes the hash of the current file and compares it with the provided value.

(o *Opts)

Source from the content-addressed store, hash-verified

124// cmpHash computes the hash of the current file and compares it with the
125// provided value.
126func cmpHash(o *Opts) (result bool, err error) {
127 hashType := "SHA1"
128 if len(o.Modifiers) > 0 {
129 hashType = o.Modifiers[0].Name
130 }
131
132 hashFunc := transform.FindHash(hashType)
133 if hashFunc == nil {
134 return false, fmt.Errorf("unexpected hash algorithm %s", hashType)
135 }
136 h, err := transform.ComputeHash(o.File, o.Path, hashFunc())
137 if err != nil {
138 return false, err
139 }
140
141 switch o.Operator {
142 case tokenizer.Equals:
143 result = h == o.Value
144 case tokenizer.NotEquals:
145 result = h != o.Value
146 default:
147 err = &ErrUnsupportedOperator{o.Attribute, o.Operator}
148 }
149 return result, err
150}

Callers 2

TestCmpHashFunction · 0.85
evaluateHashFunction · 0.85

Calls 2

FindHashFunction · 0.92
ComputeHashFunction · 0.92

Tested by 1

TestCmpHashFunction · 0.68