@@ -276,20 +276,18 @@ def from_hash(self, hash):
276
276
"""Create a `Multihash` from a hashlib-compatible `hash` object.
277
277
278
278
>>> import hashlib
279
- >>> hash = hashlib.sha1(b'foo')
279
+ >>> data = b'foo'
280
+ >>> hash = hashlib.sha1(data)
280
281
>>> digest = hash.digest()
281
282
>>> mh = Multihash.from_hash(hash)
282
283
>>> mh == (Func.sha1, digest)
283
284
True
284
285
285
- If there is no matching multihash hash function for the given `hash`,
286
- a `KeyError` is raised .
286
+ Application-specific hash functions are also supported (see
287
+ `FuncHash`) .
287
288
288
- >>> hash = hashlib.sha224(b'foo')
289
- >>> mh = Multihash.from_hash(hash)
290
- Traceback (most recent call last):
291
- ...
292
- ValueError: ('no matching multihash function', 'sha224')
289
+ If there is no matching multihash hash function for the given `hash`,
290
+ a `ValueError` is raised.
293
291
"""
294
292
try :
295
293
func = FuncHash .func_from_hash (hash )
@@ -334,18 +332,9 @@ def verify(self, data):
334
332
>>> mh.verify(b'foobar')
335
333
False
336
334
337
- Application-specific hash functions are currently not supported and a
338
- `ValueError` is raised:
339
-
340
- >>> mh = Multihash(0x01, b'TEST')
341
- >>> mh.verify(data)
342
- Traceback (most recent call last):
343
- ...
344
- ValueError: ('cannot verify with app-specific hash function', 1)
335
+ Application-specific hash functions are also supported (see
336
+ `FuncHash`).
345
337
"""
346
- if self .func not in Func :
347
- raise ValueError ("cannot verify with app-specific hash function" ,
348
- self .func )
349
338
hash = FuncHash .hash_from_func (self .func )
350
339
if not hash :
351
340
raise ValueError ("no available hash function for hash" , self .func )
0 commit comments