diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-05-15 16:28:11 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-05-15 16:29:55 +0200 |
commit | a25ef6974e0ba3989f6205c19a1f9ccfc81db584 (patch) | |
tree | 4ce3b386923515a662051c40f67a135ee15681f6 /ffi/lang | |
parent | 36e2d97ac013e023feb27df939c3f6d6e32d8669 (diff) |
core, store, tool: Use realm instead of domain.
- Remove the domain parameter from core::Context.
- Replace it with a realm to be passed in when opening a store.
- For sq, merge store name and realm into the --store parameter.
- Fixes #105.
Diffstat (limited to 'ffi/lang')
-rw-r--r-- | ffi/lang/python/Makefile | 2 | ||||
-rw-r--r-- | ffi/lang/python/examples/decrypt.py | 3 | ||||
-rw-r--r-- | ffi/lang/python/sequoia/core.py | 4 | ||||
-rw-r--r-- | ffi/lang/python/sequoia/glue.py | 4 | ||||
-rw-r--r-- | ffi/lang/python/sequoia/store.py | 12 | ||||
-rw-r--r-- | ffi/lang/python/tests/test_armor.py | 3 | ||||
-rw-r--r-- | ffi/lang/python/tests/test_packet_parser.py | 3 | ||||
-rw-r--r-- | ffi/lang/python/tests/test_store.py | 16 | ||||
-rw-r--r-- | ffi/lang/python/tests/test_tpk.py | 24 |
9 files changed, 35 insertions, 36 deletions
diff --git a/ffi/lang/python/Makefile b/ffi/lang/python/Makefile index f398c0c2..429a133e 100644 --- a/ffi/lang/python/Makefile +++ b/ffi/lang/python/Makefile @@ -50,7 +50,7 @@ ifneq "$(PYTHON)" "disable" cp build/*/_sequoia.abi*.so . # XXX can we get setuptools to do that? LDFLAGS=-L$(CARGO_TARGET_DIR)/debug LD_LIBRARY_PATH=$(CARGO_TARGET_DIR)/debug \ $(IPYTHON) -i -c \ -'from sequoia.prelude import *; ctx = Context("org.sequoia-pgp.tests.interactive")' +'from sequoia.prelude import *; ctx = Context()' endif # Installation. diff --git a/ffi/lang/python/examples/decrypt.py b/ffi/lang/python/examples/decrypt.py index c65f151d..1f4109e1 100644 --- a/ffi/lang/python/examples/decrypt.py +++ b/ffi/lang/python/examples/decrypt.py @@ -5,8 +5,7 @@ from enum import Enum, auto from sequoia.core import Context, NetworkPolicy from sequoia.openpgp import Tag, PacketParser -ctx = Context("org.sequoia-pgp.examples", - network_policy=NetworkPolicy.Offline, +ctx = Context(network_policy=NetworkPolicy.Offline, ephemeral=True) class State(Enum): diff --git a/ffi/lang/python/sequoia/core.py b/ffi/lang/python/sequoia/core.py index a7e12808..b985247b 100644 --- a/ffi/lang/python/sequoia/core.py +++ b/ffi/lang/python/sequoia/core.py @@ -18,12 +18,12 @@ class IPCPolicy(Enum): class Context(SQObject): _del = lib.sq_context_free - def __init__(self, domain, + def __init__(self, home=None, network_policy=NetworkPolicy.Encrypted, ipc_policy=IPCPolicy.Robust, ephemeral=False): - cfg = lib.sq_context_configure(domain.encode()) + cfg = lib.sq_context_configure() if home: lib.sq_config_home(cfg, home.encode()) lib.sq_config_network_policy(cfg, network_policy.value) diff --git a/ffi/lang/python/sequoia/glue.py b/ffi/lang/python/sequoia/glue.py index ea40d20c..cca3a71d 100644 --- a/ffi/lang/python/sequoia/glue.py +++ b/ffi/lang/python/sequoia/glue.py @@ -109,6 +109,10 @@ def sq_str(s): return t _str = sq_str +def sq_static_str(s): + return ffi.string(s).decode() +_static_str = sq_static_str + def sq_iterator(iterator, next_fn, map=lambda x: x): while True: entry = next_fn(iterator) diff --git a/ffi/lang/python/sequoia/store.py b/ffi/lang/python/sequoia/store.py index 4a7a41a9..c9ce84e8 100644 --- a/ffi/lang/python/sequoia/store.py +++ b/ffi/lang/python/sequoia/store.py @@ -1,12 +1,18 @@ from _sequoia import ffi, lib from .error import Error -from .glue import _str, SQObject, sq_iterator, sq_time +from .glue import _str, _static_str, SQObject, sq_iterator, sq_time from .openpgp import Fingerprint, TPK class Store(SQObject): _del = lib.sq_store_free + # Keys used for communications. + REALM_CONTACTS = _static_str(lib.SQ_REALM_CONTACTS) + + # Keys used for signing software updates. + REALM_SOFTWARE_UPDATES = _static_str(lib.SQ_REALM_SOFTWARE_UPDATES) + @classmethod def server_log(cls, ctx): yield from sq_iterator( @@ -34,8 +40,8 @@ class Store(SQObject): next_fn) @classmethod - def open(cls, ctx, name): - return Store(lib.sq_store_open(ctx.ref(), name.encode()), context=ctx) + def open(cls, ctx, realm=REALM_CONTACTS, name="default"): + return Store(lib.sq_store_open(ctx.ref(), realm.encode(), name.encode()), context=ctx) def add(self, label, fingerprint): diff --git a/ffi/lang/python/tests/test_armor.py b/ffi/lang/python/tests/test_armor.py index e439f612..93486703 100644 --- a/ffi/lang/python/tests/test_armor.py +++ b/ffi/lang/python/tests/test_armor.py @@ -7,8 +7,7 @@ from sequoia.openpgp import ArmorReader, ArmorWriter, Kind TEST_VECTORS = [0, 1, 2, 3, 47, 48, 49, 50, 51] -ctx = Context("org.sequoia-pgp.tests", - network_policy=NetworkPolicy.Offline, +ctx = Context(network_policy=NetworkPolicy.Offline, ephemeral=True) def fn_bin(t): diff --git a/ffi/lang/python/tests/test_packet_parser.py b/ffi/lang/python/tests/test_packet_parser.py index de126bc3..e50a58f5 100644 --- a/ffi/lang/python/tests/test_packet_parser.py +++ b/ffi/lang/python/tests/test_packet_parser.py @@ -6,8 +6,7 @@ pgp = "../../../openpgp/tests/data/messages/encrypted-aes128-password-123456789. plain = "../../../openpgp/tests/data/messages/a-cypherpunks-manifesto.txt" def test_decryption(): - ctx = Context("org.sequoia-pgp.tests", - network_policy=NetworkPolicy.Offline, + ctx = Context(network_policy=NetworkPolicy.Offline, ephemeral=True) class State(Enum): diff --git a/ffi/lang/python/tests/test_store.py b/ffi/lang/python/tests/test_store.py index 0c86a689..454afb7d 100644 --- a/ffi/lang/python/tests/test_store.py +++ b/ffi/lang/python/tests/test_store.py @@ -1,18 +1,18 @@ from sequoia.prelude import Context, Store, Fingerprint def test_open(): - c = Context("org.sequoia-pgp.tests", ephemeral=True) - Store.open(c, "default") + c = Context(ephemeral=True) + Store.open(c) def test_add(): - c = Context("org.sequoia-pgp.tests", ephemeral=True) - s = Store.open(c, "default") + c = Context(ephemeral=True) + s = Store.open(c) fp = Fingerprint.from_hex("7DCA58B54EB143169DDEE15F247F6DABC84914FE") s.add("Ἀριστοτέλης", fp) def test_iterate(): - c = Context("org.sequoia-pgp.tests", ephemeral=True) - s = Store.open(c, "default") + c = Context(ephemeral=True) + s = Store.open(c) fp = Fingerprint.from_hex("7DCA58B54EB143169DDEE15F247F6DABC84914FE") s.add("Ἀριστοτέλης", fp) l = list(s.iter()) @@ -23,8 +23,8 @@ def test_iterate(): assert fpi == fp def test_logs(): - c = Context("org.sequoia-pgp.tests", ephemeral=True) - s = Store.open(c, "default") + c = Context(ephemeral=True) + s = Store.open(c) fp = Fingerprint.from_hex("7DCA58B54EB143169DDEE15F247F6DABC84914FE") b = s.add("Ἀριστοτέλης", fp) l = list(s.iter()) diff --git a/ffi/lang/python/tests/test_tpk.py b/ffi/lang/python/tests/test_tpk.py index c630798f..5e06bd93 100644 --- a/ffi/lang/python/tests/test_tpk.py +++ b/ffi/lang/python/tests/test_tpk.py @@ -9,16 +9,14 @@ asc = "../../../openpgp/tests/data/keys/testy.asc" fp = Fingerprint.from_hex("3E8877C877274692975189F5D03F6F865226FE8B") def test_from_reader(): - ctx = Context("org.sequoia-pgp.tests", - network_policy=NetworkPolicy.Offline, + ctx = Context(network_policy=NetworkPolicy.Offline, ephemeral=True) r = Reader.open(ctx, pgp) t = TPK.from_reader(ctx, r) assert t.fingerprint() == fp def test_from_armor_reader(): - ctx = Context("org.sequoia-pgp.tests", - network_policy=NetworkPolicy.Offline, + ctx = Context(network_policy=NetworkPolicy.Offline, ephemeral=True) k = open(asc, "rb").read() r = Reader.from_bytes(ctx, k) @@ -27,30 +25,26 @@ def test_from_armor_reader(): assert t.fingerprint() == fp def test_from_file(): - ctx = Context("org.sequoia-pgp.tests", - network_policy=NetworkPolicy.Offline, + ctx = Context(network_policy=NetworkPolicy.Offline, ephemeral=True) t = TPK.open(ctx, pgp) assert t.fingerprint() == fp def test_from_packet_pile(): - ctx = Context("org.sequoia-pgp.tests", - network_policy=NetworkPolicy.Offline, + ctx = Context(network_policy=NetworkPolicy.Offline, ephemeral=True) r = PacketPile.open(ctx, pgp) t = TPK.from_packet_pile(ctx, r) assert t.fingerprint() == fp def test_from_bytes(): - ctx = Context("org.sequoia-pgp.tests", - network_policy=NetworkPolicy.Offline, + ctx = Context(network_policy=NetworkPolicy.Offline, ephemeral=True) t = TPK.from_bytes(ctx, open(pgp, "rb").read()) assert t.fingerprint() == fp def test_from_serialize(): - ctx = Context("org.sequoia-pgp.tests", - network_policy=NetworkPolicy.Offline, + ctx = Context(network_policy=NetworkPolicy.Offline, ephemeral=True) with TemporaryDirectory() as tmp: sink = join(tmp, "a") @@ -63,8 +57,7 @@ def test_from_serialize(): assert t.fingerprint() == fp def test_equals(): - ctx = Context("org.sequoia-pgp.tests", - network_policy=NetworkPolicy.Offline, + ctx = Context(network_policy=NetworkPolicy.Offline, ephemeral=True) b = open(pgp, "rb").read() t = TPK.from_bytes(ctx, b) @@ -72,8 +65,7 @@ def test_equals(): assert t == u def test_clone(): - ctx = Context("org.sequoia-pgp.tests", - network_policy=NetworkPolicy.Offline, + ctx = Context(network_policy=NetworkPolicy.Offline, ephemeral=True) a = TPK.open(ctx, pgp) b = a.copy() |