appid and derive_key(purpose=) must be bytes, not unicode
This commit is contained in:
parent
e8626fcea2
commit
5d93dccb88
11
docs/api.md
11
docs/api.md
|
@ -53,7 +53,7 @@ The synchronous+blocking flow looks like this:
|
|||
from wormhole.blocking.transcribe import Wormhole
|
||||
from wormhole.public_relay import RENDEZVOUS_RELAY
|
||||
mydata = b"initiator's data"
|
||||
i = Wormhole("appid", RENDEZVOUS_RELAY)
|
||||
i = Wormhole(b"appid", RENDEZVOUS_RELAY)
|
||||
code = i.get_code()
|
||||
print("Invitation Code: %s" % code)
|
||||
theirdata = i.get_data(mydata)
|
||||
|
@ -66,7 +66,7 @@ from wormhole.blocking.transcribe import Wormhole
|
|||
from wormhole.public_relay import RENDEZVOUS_RELAY
|
||||
mydata = b"receiver's data"
|
||||
code = sys.argv[1]
|
||||
r = Wormhole("appid", RENDEZVOUS_RELAY)
|
||||
r = Wormhole(b"appid", RENDEZVOUS_RELAY)
|
||||
r.set_code(code)
|
||||
theirdata = r.get_data(mydata)
|
||||
print("Their data: %s" % theirdata.decode("ascii"))
|
||||
|
@ -81,7 +81,7 @@ from twisted.internet import reactor
|
|||
from wormhole.public_relay import RENDEZVOUS_RELAY
|
||||
from wormhole.twisted.transcribe import Wormhole
|
||||
outbound_message = b"outbound data"
|
||||
w1 = Wormhole("appid", RENDEZVOUS_RELAY)
|
||||
w1 = Wormhole(b"appid", RENDEZVOUS_RELAY)
|
||||
d = w1.get_code()
|
||||
def _got_code(code):
|
||||
print "Invitation Code:", code
|
||||
|
@ -97,7 +97,7 @@ reactor.run()
|
|||
On the other side, you call `set_code()` instead of waiting for `get_code()`:
|
||||
|
||||
```python
|
||||
w2 = Wormhole("appid", RENDEZVOUS_RELAY)
|
||||
w2 = Wormhole(b"appid", RENDEZVOUS_RELAY)
|
||||
w2.set_code(code)
|
||||
d = w2.get_data(my_message)
|
||||
...
|
||||
|
@ -140,7 +140,8 @@ simple bytestring that distinguishes one application from another. To ensure
|
|||
uniqueness, use a domain name. To use multiple apps for a single domain, just
|
||||
use a string like `example.com/app1`. This string must be the same on both
|
||||
clients, otherwise they will not see each other. The invitation codes are
|
||||
scoped to the app-id.
|
||||
scoped to the app-id. Note that the app-id must be a bytestring, not unicode,
|
||||
so on python3 use `b"appid"`.
|
||||
|
||||
Distinct app-ids reduce the size of the connection-id numbers. If fewer than
|
||||
ten initiators are active for a given app-id, the connection-id will only
|
||||
|
|
|
@ -29,6 +29,7 @@ class Wormhole:
|
|||
version_warning_displayed = False
|
||||
|
||||
def __init__(self, appid, relay):
|
||||
if not isinstance(appid, type(b"")): raise UsageError
|
||||
self.appid = appid
|
||||
self.relay = relay
|
||||
if not self.relay.endswith("/"): raise UsageError
|
||||
|
|
|
@ -2,7 +2,7 @@ from __future__ import print_function
|
|||
import sys, os, json, binascii
|
||||
from ..errors import handle_server_error
|
||||
|
||||
APPID = "lothar.com/wormhole/file-xfer"
|
||||
APPID = b"lothar.com/wormhole/file-xfer"
|
||||
|
||||
@handle_server_error
|
||||
def receive_file(args):
|
||||
|
@ -50,7 +50,7 @@ def receive_file(args):
|
|||
|
||||
# now receive the rest of the owl
|
||||
tdata = data["transit"]
|
||||
transit_key = w.derive_key(APPID+"/transit-key")
|
||||
transit_key = w.derive_key(APPID+b"/transit-key")
|
||||
transit_receiver.set_transit_key(transit_key)
|
||||
transit_receiver.add_their_direct_hints(tdata["direct_connection_hints"])
|
||||
transit_receiver.add_their_relay_hints(tdata["relay_connection_hints"])
|
||||
|
|
|
@ -2,7 +2,7 @@ from __future__ import print_function
|
|||
import sys, json, binascii
|
||||
from ..errors import handle_server_error
|
||||
|
||||
APPID = "lothar.com/wormhole/text-xfer"
|
||||
APPID = b"lothar.com/wormhole/text-xfer"
|
||||
|
||||
@handle_server_error
|
||||
def receive_text(args):
|
||||
|
|
|
@ -2,7 +2,7 @@ from __future__ import print_function
|
|||
import os, sys, json, binascii
|
||||
from ..errors import handle_server_error
|
||||
|
||||
APPID = "lothar.com/wormhole/file-xfer"
|
||||
APPID = b"lothar.com/wormhole/file-xfer"
|
||||
|
||||
@handle_server_error
|
||||
def send_file(args):
|
||||
|
@ -70,7 +70,7 @@ def send_file(args):
|
|||
|
||||
|
||||
tdata = them_d["transit"]
|
||||
transit_key = w.derive_key(APPID+"/transit-key")
|
||||
transit_key = w.derive_key(APPID+b"/transit-key")
|
||||
transit_sender.set_transit_key(transit_key)
|
||||
transit_sender.add_their_direct_hints(tdata["direct_connection_hints"])
|
||||
transit_sender.add_their_relay_hints(tdata["relay_connection_hints"])
|
||||
|
|
|
@ -2,7 +2,7 @@ from __future__ import print_function
|
|||
import sys, json, binascii
|
||||
from ..errors import handle_server_error
|
||||
|
||||
APPID = "lothar.com/wormhole/text-xfer"
|
||||
APPID = b"lothar.com/wormhole/text-xfer"
|
||||
|
||||
@handle_server_error
|
||||
def send_text(args):
|
||||
|
|
|
@ -10,7 +10,7 @@ class Blocking(ServerBase, unittest.TestCase):
|
|||
# with deferToThread()
|
||||
|
||||
def test_basic(self):
|
||||
appid = "appid"
|
||||
appid = b"appid"
|
||||
w1 = BlockingWormhole(appid, self.relayurl)
|
||||
w2 = BlockingWormhole(appid, self.relayurl)
|
||||
d = deferToThread(w1.get_code)
|
||||
|
@ -31,7 +31,7 @@ class Blocking(ServerBase, unittest.TestCase):
|
|||
return d
|
||||
|
||||
def test_fixed_code(self):
|
||||
appid = "appid"
|
||||
appid = b"appid"
|
||||
w1 = BlockingWormhole(appid, self.relayurl)
|
||||
w2 = BlockingWormhole(appid, self.relayurl)
|
||||
w1.set_code("123-purple-elephant")
|
||||
|
@ -50,7 +50,7 @@ class Blocking(ServerBase, unittest.TestCase):
|
|||
return d
|
||||
|
||||
def test_errors(self):
|
||||
appid = "appid"
|
||||
appid = b"appid"
|
||||
w1 = BlockingWormhole(appid, self.relayurl)
|
||||
self.assertRaises(UsageError, w1.get_verifier)
|
||||
self.assertRaises(UsageError, w1.get_data, "data")
|
||||
|
@ -65,7 +65,7 @@ class Blocking(ServerBase, unittest.TestCase):
|
|||
return d
|
||||
|
||||
def test_serialize(self):
|
||||
appid = "appid"
|
||||
appid = b"appid"
|
||||
w1 = BlockingWormhole(appid, self.relayurl)
|
||||
self.assertRaises(UsageError, w1.serialize) # too early
|
||||
w2 = BlockingWormhole(appid, self.relayurl)
|
||||
|
|
|
@ -9,7 +9,7 @@ from .common import ServerBase
|
|||
|
||||
class Basic(ServerBase, unittest.TestCase):
|
||||
def test_basic(self):
|
||||
appid = "appid"
|
||||
appid = b"appid"
|
||||
w1 = Wormhole(appid, self.relayurl)
|
||||
w2 = Wormhole(appid, self.relayurl)
|
||||
d = w1.get_code()
|
||||
|
@ -30,7 +30,7 @@ class Basic(ServerBase, unittest.TestCase):
|
|||
return d
|
||||
|
||||
def test_fixed_code(self):
|
||||
appid = "appid"
|
||||
appid = b"appid"
|
||||
w1 = Wormhole(appid, self.relayurl)
|
||||
w2 = Wormhole(appid, self.relayurl)
|
||||
w1.set_code("123-purple-elephant")
|
||||
|
@ -49,7 +49,7 @@ class Basic(ServerBase, unittest.TestCase):
|
|||
return d
|
||||
|
||||
def test_errors(self):
|
||||
appid = "appid"
|
||||
appid = b"appid"
|
||||
w1 = Wormhole(appid, self.relayurl)
|
||||
self.assertRaises(UsageError, w1.get_verifier)
|
||||
self.assertRaises(UsageError, w1.get_data, "data")
|
||||
|
@ -62,7 +62,7 @@ class Basic(ServerBase, unittest.TestCase):
|
|||
return d
|
||||
|
||||
def test_serialize(self):
|
||||
appid = "appid"
|
||||
appid = b"appid"
|
||||
w1 = Wormhole(appid, self.relayurl)
|
||||
self.assertRaises(UsageError, w1.serialize) # too early
|
||||
w2 = Wormhole(appid, self.relayurl)
|
||||
|
|
|
@ -38,6 +38,7 @@ class Wormhole:
|
|||
version_warning_displayed = False
|
||||
|
||||
def __init__(self, appid, relay):
|
||||
if not isinstance(appid, type(b"")): raise UsageError
|
||||
self.appid = appid
|
||||
self.relay = relay
|
||||
self.agent = web_client.Agent(reactor)
|
||||
|
|
Loading…
Reference in New Issue
Block a user