self._client = client
self._pubkey = None # filled in upon first read
self._privkey = None # filled in if we're mutable
+ self._required_shares = None # ditto
+ self._total_shares = None # ditto
self._sharemap = {} # known shares, shnum-to-[nodeids]
self._current_data = None # SDMF: we're allowed to cache the contents
the initial contents. Returns a Deferred that fires (with the
MutableFileNode instance you should use) when it completes.
"""
- self._privkey = "very private"
- self._pubkey = "public"
- self._writekey = hashutil.ssk_writekey_hash(self._privkey)
+ self._required_shares = 3
+ self._total_shares = 10
+ self._pubkey, self._privkey = self._generate_pubprivkeys()
+ pubkey_s = self._pubkey.serialize()
privkey_s = self._privkey.serialize()
+ self._writekey = hashutil.ssk_writekey_hash(privkey_s)
self._encprivkey = self._encrypt_privkey(self._writekey, privkey_s)
- pubkey_s = self._pubkey.serialize()
self._fingerprint = hashutil.ssk_pubkey_fingerprint_hash(pubkey_s)
self._uri = WriteableSSKFileURI(self._writekey, self._fingerprint)
- self._current_seqnum = 0
+ self._readkey = self._uri.readkey
+ self._storage_index = self._uri.storage_index
+ self._current_seqnum = 0 # TODO: really we mean "doesn't matter
+ # since nobody knows about us yet"
self._current_roothash = "\x00"*32
return self._publish(initial_contents)
+ def _generate_pubprivkeys(self):
+ privkey = "very private"
+ pubkey = "public"
+ return pubkey, privkey
+
def _publish(self, initial_contents):
# TODO: actually do all that stuff
p = Publish(self)
return self._pubkey
def get_required_shares(self):
- return 3 # TODO: where should this come from?
+ return self._required_shares
def get_total_shares(self):
- return 10 # TODO: same
+ return self._total_shares
def get_uri(self):
counter = itertools.count(1)
all_contents = {}
- def create(self, initial_contents):
+ def _generate_pubprivkeys(self):
count = self.counter.next()
- self.init_from_uri(uri.WriteableSSKFileURI("key%d" % count,
- "fingerprint%d" % count))
+ return FakePubKey(count), FakePrivKey(count)
+ def _publish(self, initial_contents):
self.all_contents[self._uri] = initial_contents
- self._privkey = FakePrivKey()
- self._pubkey = FakePubKey()
- self._encprivkey = "encrypted private key"
- privkey_s = self._privkey.serialize()
- #self._encprivkey = self._encrypt_privkey(self._writekey, privkey_s)
- pubkey_s = self._pubkey.serialize()
- self._fingerprint = hashutil.ssk_pubkey_fingerprint_hash(pubkey_s)
- self._current_seqnum = 0
- self._current_roothash = "\x00"*32
return defer.succeed(self)
+
def download_to_data(self):
return defer.succeed(self.all_contents[self._uri])
def replace(self, newdata):
len(CONTENTS),
"IV"*8),
3, # seqnum
- FakePrivKey(), "encprivkey", FakePubKey(),
+ FakePrivKey(0), "encprivkey", FakePubKey(0),
)
def _done( (seqnum, root_hash, final_shares) ):
self.failUnlessEqual(seqnum, 3)
self.failUnlessEqual(sorted(final_shares.keys()), range(10))
for i,sh in final_shares.items():
self.failUnless(isinstance(sh, str))
- self.failUnlessEqual(len(sh), 367)
+ self.failUnlessEqual(len(sh), 369)
# feed the share through the unpacker as a sanity-check
pieces = mutable.unpack_share(sh)
(u_seqnum, u_root_hash, k, N, segsize, datalen,
self.failUnlessEqual(N, 10)
self.failUnlessEqual(segsize, 21)
self.failUnlessEqual(datalen, len(CONTENTS))
- self.failUnlessEqual(pubkey, FakePubKey().serialize())
+ self.failUnlessEqual(pubkey, FakePubKey(0).serialize())
sig_material = struct.pack(">BQ32s BBQQ", 0, seqnum, root_hash,
k, N, segsize, datalen)
self.failUnlessEqual(signature,
- FakePrivKey().sign(sig_material))
+ FakePrivKey(0).sign(sig_material))
self.failUnless(isinstance(share_hash_chain, list))
self.failUnlessEqual(len(share_hash_chain), 4) # ln2(10)++
for i in share_hash_chain:
len(CONTENTS),
"IV"*8),
3, # seqnum
- FakePrivKey(), "encprivkey", FakePubKey(),
+ FakePrivKey(0), "encprivkey", FakePubKey(0),
)
return d, p
def test_publish(self):
c, fn, p = self.setup_for_publish(20)
- d = p.publish("new contents of the mutable filenode")
+ # make sure the length of our contents string is not a multiple of k,
+ # to exercise the padding code.
+ d = p.publish("New contents of the mutable filenode.")
def _done(res):
# TODO: examine peers and check on their shares
pass
class FakePubKey:
+ def __init__(self, count):
+ self.count = count
def serialize(self):
- return "PUBKEY"
+ return "PUBKEY-%d" % self.count
class FakePrivKey:
+ def __init__(self, count):
+ self.count = count
def serialize(self):
- return "PRIVKEY"
+ return "PRIVKEY-%d" % self.count
def sign(self, data):
return "SIGN(%s)" % data