def write_ots(self):
     assert self.status == "complete"
     assert self.block == sorted(roll_timestamp(self.detached_timestamp.timestamp).attestations)[0].height
     ctx = BytesSerializationContext()
     self.detached_timestamp.serialize(ctx)
     with open(self.path + ".ots", "wb") as fw:
         fw.write(ctx.getbytes())
Example #2
0
    def __kv_map_to_bytes(kv_map):
        ctx = BytesSerializationContext()
        # Sorting the map elements to create chunks deterministically, but this is not mandatory for importing the chunk
        for key, value in sorted(kv_map.items()):
            ctx.write_varuint(len(key))
            ctx.write_bytes(key)
            ctx.write_varuint(len(value))
            ctx.write_bytes(value)

        return ctx.getbytes()
Example #3
0
    def __put_timestamp(self, new_timestamp, batch):
        """Write a single timestamp, non-recursively"""
        ctx = BytesSerializationContext()

        ctx.write_varuint(len(new_timestamp.attestations))
        for attestation in new_timestamp.attestations:
            attestation.serialize(ctx)

        ctx.write_varuint(len(new_timestamp.ops))
        for op in new_timestamp.ops:
            op.serialize(ctx)

        batch.Put(new_timestamp.msg, ctx.getbytes())
    def __put_timestamp(self, new_timestamp, batch):
        """Write a single timestamp, non-recursively"""
        ctx = BytesSerializationContext()

        ctx.write_varuint(len(new_timestamp.attestations))
        for attestation in new_timestamp.attestations:
            attestation.serialize(ctx)

        ctx.write_varuint(len(new_timestamp.ops))
        for op in new_timestamp.ops:
            op.serialize(ctx)

        batch.Put(new_timestamp.msg, ctx.getbytes())
def write_ascii_armored(timestamp, fd, minor_version):
    ctx = BytesSerializationContext()
    timestamp.serialize(ctx)
    serialized_timestamp = ctx.getbytes()

    fd.write(ASCII_ARMOR_HEADER)

    header = (b'\x01' + # major
              bytes([minor_version]))
    b64_encoded = base64.standard_b64encode(header + serialized_timestamp)
    for chunk in (b64_encoded[i:i+64] for i in range(0, len(b64_encoded), 64)):
        fd.write(chunk)
        fd.write(b'\n')

    fd.write(ASCII_ARMOR_FOOTER)
Example #6
0
    def __create_kv_map(ts, msg, kv_map):
        ctx = BytesSerializationContext()

        ctx.write_varuint(len(ts.attestations))
        for attestation in ts.attestations:
            attestation.serialize(ctx)

        ctx.write_varuint(len(ts.ops))
        for op in ts.ops:
            op.serialize(ctx)

        kv_map[msg] = ctx.getbytes()

        for op, timestamp in ts.ops.items():
            Backup.__create_kv_map(timestamp, timestamp.msg, kv_map)
 def as_dict(self):
     d = dict()
     d["path"] = self.path
     d["status"] = self.status
     d["agt"] = self.agt.hex() if self.agt else self.agt
     d["txid"] = self.txid
     d["block"] = self.block
     d["date"] = self.date
     pre_serialize(self.detached_timestamp.timestamp)
     ctx = BytesSerializationContext()
     self.detached_timestamp.serialize(ctx)
     d["detached_timestamp"] = bytes_to_b64string(ctx.getbytes())
     ft = roll_timestamp(self.detached_timestamp.timestamp)
     ft.attestations = set()
     return d
Example #8
0
def serialize(timestamp):
    '''timestamp arg is Timestamp or DetachedTimestampFile'''
    ctx = BytesSerializationContext()
    timestamp.serialize(ctx)
    return ctx.getbytes()