Skip to content

Commit bc5cc89

Browse files
committed
Replace need for DefaultLength in opts processing.
This creates a hasher long enough to ask it its properties. This is arguably creating garbage; on the other hand, I don't think this is a codepath ever likely to be used in a hot loop anywhere. We can extract this to something that caches the properties later if it proves necessary. It quietly defaults to zero for unknown codes. I don't know if this makes sense, but it's what the old code would have done, so it's what the new code will do, and I'm not looking deeper into it. At this point I'm just trying to make surgically minimal alterations and get this changeset as a whole wrapped up so things can move on.
1 parent 67c208a commit bc5cc89

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

opts/opts.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,13 @@ func (o *Options) ParseError() error {
110110
}
111111
o.Length = o.Length / 8
112112

113-
if o.Length > mh.DefaultLengths[o.AlgorithmCode] {
114-
o.Length = mh.DefaultLengths[o.AlgorithmCode]
113+
h, _ := mh.GetHasher(o.AlgorithmCode)
114+
hsize := 0
115+
if h != nil {
116+
hsize = h.Size()
117+
}
118+
if o.Length > hsize {
119+
o.Length = hsize
115120
}
116121
}
117122
return nil

0 commit comments

Comments
 (0)