跳转到主要内容

哈希链日志实现

项目描述

HashLog

Coverage Status

原则

  • 记录是不可变的
  • 记录是有序的
  • 必须能够检查任何 ihash(Xi)
  • hash(Xi) 可以发送给任何人作为证据
  • hash(Xi) == hash(X, hash(Xi-1))
  • 您不需要 X 来执行检查

安装

$ pip install hlog

使用

入门

# create a chain
c = Chain()

# send some messages
c.append(message="Alice gives 10.36 euros to Bob", amount=10.36, currency="EUR")
c.append(message="Bob gives 2 dollars to Alice", amount=2, currency="USD")

# you can loop through the chain records
used_currencies = set(r.fields["currency"] for r in c.records)

# call verify() to ensure records have not been modified
c.verify()

验证期间抛出异常

c.verify(raise_on_error=True)

Verify 将抛出 ModifiedRecordException。它有 3 个有趣的属性

  • index:验证失败的链中索引
  • message:一个用户友好的消息,指示错误
  • record:本身的 Record 对象

转储

c = Chain()
c.append(message="hello")
c.append(message="wonderful")
c.append(message="world")

rows = c.dump()

rows 是一个 tuplebytes,每个项是链中的一个记录。

从转储中恢复

如果您想根据文件或数据库记录重建链,可以使用 Chain.from_dump()

c = Chain()
c.append(message="hello")
c.append(message="wonderful")
c.append(message="world")

d = c.dump()

c2 = Chain.from_dump(d)

c2.verify()

项目详情


下载文件

下载您平台上的文件。如果您不确定要选择哪个,请了解有关 安装包 的更多信息。

源分布

hlog-1.0.1.tar.gz (5.9 kB 查看哈希)

上传时间:

由以下赞助

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面