2 from allmydata.util import idlib
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]).
8 def pack_uri(codec_name, codec_params, verifierid, roothash, needed_shares, total_shares, size, segment_size):
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:%s:%s:%s:%s:%s" % (codec_name, codec_params, idlib.b2a(verifierid), idlib.b2a(roothash), needed_shares, total_shares, size, segment_size)
20 assert uri.startswith("URI:")
21 header, codec_name, codec_params, verifierid_s, roothash_s, needed_shares_s, total_shares_s, size_s, segment_size_s = uri.split(":")
22 verifierid = idlib.a2b(verifierid_s)
23 roothash = idlib.a2b(roothash_s)
24 needed_shares = idlib.a2b(needed_shares_s)
25 total_shares = idlib.a2b(total_shares_s)
27 segment_size = int(segment_size_s)
28 return codec_name, codec_params, verifierid, roothash, needed_shares, total_shares, size, segment_size