]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/uri.py
update URI format, include codec name
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / uri.py
1
2 from allmydata.util import bencode, idlib
3
4 # the URI shall be an ascii representation of the file. It shall contain
5 # enough information to retrieve and validate the contents. It shall be
6 # expressed in a limited character set (namely [TODO]).
7
8 def pack_uri(codec_name, codec_params, verifierid):
9     assert isinstance(codec_name, str)
10     assert len(codec_name) < 10
11     assert ":" not in codec_name
12     assert isinstance(codec_params, str)
13     assert ":" not in codec_params
14     assert isinstance(verifierid, str)
15     assert len(verifierid) == 20 # sha1 hash
16     return "URI:%s:%s:%s" % (codec_name, codec_params, idlib.b2a(verifierid))
17
18
19 def unpack_uri(uri):
20     assert uri.startswith("URI:")
21     header, codec_name, codec_params, verifierid_s = uri.split(":")
22     verifierid = idlib.a2b(verifierid_s)
23     return codec_name, codec_params, verifierid
24
25