from allmydata.util import hashutil, mathutil, base32, log
from allmydata.util.hashutil import netstring
from allmydata.util.limiter import ConcurrencyLimiter
+from allmydata.util.netstring import split_netstring
from allmydata.uri import NewDirectoryURI
from pycryptopp.cipher.aes import AES
-def split_netstring(data, numstrings, allow_leftover=False):
- """like string.split(), but extracts netstrings. If allow_leftover=False,
- returns numstrings elements, and throws ValueError if there was leftover
- data. If allow_leftover=True, returns numstrings+1 elements, in which the
- last element is the leftover data (possibly an empty string)"""
- elements = []
- assert numstrings >= 0
- while data:
- colon = data.index(":")
- length = int(data[:colon])
- string = data[colon+1:colon+1+length]
- assert len(string) == length
- elements.append(string)
- assert data[colon+1+length] == ","
- data = data[colon+1+length+1:]
- if len(elements) == numstrings:
- break
- if len(elements) < numstrings:
- raise ValueError("ran out of netstrings")
- if allow_leftover:
- return tuple(elements + [data])
- if data:
- raise ValueError("leftover data in netstrings")
- return tuple(elements)
-
class Deleter:
def __init__(self, node, name, must_exist=True):
self.node = node
from pycryptopp.hash.sha256 import SHA256
import os
+from allmydata.util.netstring import netstring
# Be very very cautious when modifying this file. Almost any change will
# cause a compatibility break, invalidating all outstanding URIs and making
class IntegrityCheckError(Exception):
pass
-def netstring(s):
- assert isinstance(s, str), s # no unicode here
- return "%d:%s," % (len(s), s,)
-
class _SHA256d_Hasher:
# use SHA-256d, as defined by Ferguson and Schneier: hash the output
# again to prevent length-extension attacks
--- /dev/null
+
+
+def netstring(s):
+ assert isinstance(s, str), s # no unicode here
+ return "%d:%s," % (len(s), s,)
+
+def split_netstring(data, numstrings, allow_leftover=False):
+ """like string.split(), but extracts netstrings. If allow_leftover=False,
+ returns numstrings elements, and throws ValueError if there was leftover
+ data. If allow_leftover=True, returns numstrings+1 elements, in which the
+ last element is the leftover data (possibly an empty string)"""
+ elements = []
+ assert numstrings >= 0
+ while data:
+ colon = data.index(":")
+ length = int(data[:colon])
+ string = data[colon+1:colon+1+length]
+ assert len(string) == length
+ elements.append(string)
+ assert data[colon+1+length] == ","
+ data = data[colon+1+length+1:]
+ if len(elements) == numstrings:
+ break
+ if len(elements) < numstrings:
+ raise ValueError("ran out of netstrings")
+ if allow_leftover:
+ return tuple(elements + [data])
+ if data:
+ raise ValueError("leftover data in netstrings")
+ return tuple(elements)
+