Files
palemoon27/python/PyECC/ecc/encoding.py
T
roytam1 688c3af674 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1235021 - Re-emit ChromeManifestEntries from the jar manifest handler code in the FasterMake backend. r=gps (a8d899a6da)
- Bug 1233282 - Make CONFIGURE_DEFINE_FILES considered more as GENERATED_FILES in the emitter. r=gps (d29506fb55)
- Bug 1235021 - Add a RenamedSourcePath helper class. r=gps (62e78b867b)
- Bug 1235021 - Re-emit FinalTarget{,Preprocessed}Files from the jar manifest handler code in the FasterMake backend. r=gps (c37287a5d7)
- Bug 1235021 - Avoid passing defines to FasterMakeBackend._consume_jar_manifest. r=gps (dc0d17c3a6)
- Bug 1235021 - Move FasterMakeBackend._consume_jar_manifest to CommonBackend. r=gps (b9bb6b7d1e)
- Bug 1239217 - Add the notion of Partial and Hybrid build backends. r=gps Make the FasterMake backend a partial build backend. (219c0811e6)
- Bug 1239217 - Stop making the FasterMake build system refresh the backend on its own. r=gps (4f79f966ce)
- Bug 1241398 - Show the diff for created and deleted files in `mach build-backend --diff`. r=gps (d497d3aef8)
- Bug 1214885 - Add a "ChromeUrl" build backend to write out information useful for resolving chrome urls. r=glandium (83ad13d109)
- Bug 1216817 - Part 1: Add install_callback to artifacts. r=gps (95b4860d09)
- Bug 1216817 - Part 2: Narrow distdir to bindir in artifacts. r=gps (e48b531455)
- Bug 1216817 - Part 4: Add --enable-artifact-builds and MOZ_ARTIFACT_BUILDS. r=glandium (8d7ed76621)
- bug 1164816 - Import concurrent.futures into the tree. r=gps (bc83211833)
- bug 1190603 - import PyECC library r=gps,gerv (e0c5afeee0)
- Bug 1216817 - Part 5: Run |mach artifact install| automatically when asked. r=glandium (835c27d9c2)
- Bug 1216817 - Follow-up: Fix "KeyError: uMOZ_ARTIFACT_BUILDS" in config.status. r=bustage (e87e04e23b)
- Bug 1216817 - Follow-up: Fix "KeyError: u'MOZ_ARTIFACT_BUILDS'". r=bustage (797331293b)
- Bug 1207897 - Add a configure option to build multiple build backends. r=gps (35f62c27ca)
- Bug 1241398 - Allow to pass the --verbose flag down to config.status from `mach build-backend`. r=gps (78610c40d0)
- Bug 1236111 - part 1: avoid configure.in Windows-only goop when running with disable-compile-environment, r=gps (d27a7e522a)
- Bug 1236111 - part 2: fix mozbuild to use the file mode modifiers specified for opening when writing a FileAvoidWrite, r=gps,nalexander (e240c613b7)
- Bug 1207890 - Part 1: Add rich ArtifactJob extension point. r=glandium (e402f5fcec)
- Bug 1207890 - Part 2: Stop extracting build ID from artifacts. r=glandium (314d6895c1)
- Bug 1207890 - Part 3: Post-process downloaded artifacts. r=glandium (09d60ac030)
- Bug 1207890 - Part 4: Download and process Mac OS X artifacts. r=glandium (181ba370b1)
- Bug 1207890 - Pre: Make JarWriter handle inputs with read() but not seek(). r=glandium (6ebb5dfe94)
- Bug 1207890 - Post: Hacks to make --disable-compile-environment work on Mac OS X. r=glandium (c5f88b6adf)
- Bug 1207890 - Post: Move |mach artifact| command out of mobile/android. r=glandium (a06f97dfb9)
- Bug 1207890 - Post: Hack to make |mach run| for Mac OS X artifact builds. r=me (4c6d2f6bfe)
- Bug 1207890 - Follow-up: Fix |mach artifact install| for mobile/android. r=me (a2e4347ca9)
- Bug 1236111 - part 3: ensure calls to hg and mach work on Windows, and that we use the right file mode when writing artifacts, r=nalexander,gps (d0090a5a56)
- Bug 1236111 - part 4: actually add Windows support to artifact code, r=nalexander,gps (ab40057ffa)
- Bug 1236111 - part 0: improve logging from process mixin, r=gps (d85265c134)
- Bug 1241398 - Add a dry-run mode to mach build-backend. r=gps (b300169915)
- Bug 1239217 - Make the RecursiveMake build system create backend files generically. r=gps (fba90d6bcb)
- fix minor misspatch of 1240990 (b7d44692bc)
- Bug 1239296 - Use telemetry_handler to store build resource data r=gps (58d7c3a260)
- Bug 1244143 - Record whether or not an artifact build was used in build telemetry data r=gps (d1821d1987)
- Bug 1246264 - Ensure cache directory exists for artifacts installation r=chmanchester (ef5c4a0fba)
- bug 1237619: save resource usage for "what" builds r=gps (6a311c71bc)
- Bug 1239296 - Add telemetry_handler function to mach context r=gps (4a7a67740d)
- Bug 1246402 - Environment variable to disable mercurial setup check. r=gps (d9cf129b6c)
- Bug 1239296 - add post_dispatch_handler hook to mach r=gps (aa55c9a36e)
- Bug 1236110 - Extend mach artifact to handle Linux Desktop builds. r=gps (cb29ca6d1d)
- Bug 1234912 - Check for mozext and pushlog entries after |mach artifact install| hg failure. r=gps (7bfb064c7c)
- Bug 1239096 - Improve English is artifacts.py comments. r=me (38aa5ecb19)
- Bug 1238320 - Part 1 (Linux): Download test binaries necessary to run xpcshell tests and mochitests in artifact builds. r=nalexander (f6407791ae)
- Bug 1238320 - Part 2 (Mac): Download test binaries necessary to run xpcshell tests and mochitests in artifact builds. r=nalexander (4d72cfc6f2)
- Bug 1238320 - Part 3 (Windows): Download test binaries necessary to run xpcshell tests and mochitests in artifact builds. r=nalexander# Please enter the commit message for your changes. Lines starting (40ac9f9f7d)
- Bug 1239678 - fix dll inclusion pattern on Windows and the placement of nested dlls like browsercomps and clearkey, r=nalexander (ad9015c9d9)
- Bug 1239738 - Handle artifact builds with no test binaries cleanly. r=ahunt (ba1593837a)
- Bug 1240323 - Fix installation of binary components in a subdir of dist/bin for linux artifact builds. r=nalexander (2f4b719ea3)
- Bug 1240239 - Install test plugins in artifact based builds. r=nalexander (edc24f4fd2)
- Bug 1240667 - Detect a tree to use for artifact builds based on recent changesets. r=nalexander (947879cb19)
- Bug 1244941 - Don't fill install manifest with artifacts. r=nalexander (8fa9793c53)
- Bug 1237619: Record build objects in resource_usage.json r=gps (c323d21c9f)
- bug 1237619: Add system and command metadata to resouce_usage.json r=gps (c93fb18c37)
- Bug 1240059 - Treat psutil as optional in record_resource_usage. r=gps (c91103ebce)
- Bug 1244160 - Create json-schema for build telemetry data r=gps (d8b3419cfd)
- Bug 1250624 - Overall system resources is displayed twice; r=chmanchester (a115c86902)
- Bug 1144842 (part 1) - Don't use MOZ_PROFILING before all the places it can be set. r=glandium. (3c12a2e29a)
- Bug 1144842 (part 2) - Make --enable-dmd imply --enable-profiling. r=glandium. (85c9ff5c32)
- Bug 1144842 (part 3) - Remove --enable-dmd code from js/src/configure.in. r=glandium. (52cf663bc7)
- Bug 1204260 - Pre: Don't expose ANDROID_{BUILD,PLATFORM}_TOOLS. r=glandium,gbrown (d4f560dd46)
- Bug 1219803 - Support 'mach run' for Android; r=jmaher (5a1a1ab16e)
- Bug 1219807 - Add tooltool manifests for jimdb; r=jmaher (4d7a211569)
- Bug 1221846 - Get Task Tracer building on desktop r=cyu. (5d1a0fabe9)
- Bug 1216681 - Add a fileid utility to extract the breakpad GUID from object files for identification in fix_stack_using_bpsyms. r=ted (e53eb5acc6)
- Bug 1237156 - Only build the fileid utility when MOZ_CRASHREPORTER is set. r=ted.mielczarek (328a80ae18)
- Bug 1239866 - Remove signaling standalone tests. r=bwc (b05b091059)
2023-09-27 11:04:31 +08:00

179 lines
4.5 KiB
Python

#
# Encodings and Formats for Elliptic Curve Cryptography
#
import StringIO
# Big-Endian Encoding
def enc_long(n):
'''Encodes arbitrarily large number n to a sequence of bytes.
Big endian byte order is used.'''
s = ""
while n > 0:
s = chr(n & 0xFF) + s
n >>= 8
return s
def enc_int(n):
'''Encodes an integer n to a 4-byte string.
Big endian byte order is used.'''
return chr((n >> 24) & 0xFF) + chr((n >> 16) & 0xFF) + \
chr((n >> 8) & 0xFF) + chr( n & 0xFF)
def enc_fixed_long(n, length):
return enc_long(n)[:length].rjust(length, '\x00')
def dec_long(s):
'''Decodes s to its numeric representation.
Big endian byte order is used.'''
n = 0
for c in s:
n = (n << 8) | ord(c)
return n
# dec_int not necessary,
# dec_long does the same when provided with 4 bytes input.
# Chunks
def enc_chunks(*args):
'''Chain given string args or sub-chunks to a single chunk'''
return ''.join([enc_int(len(a)) + a for a in args])
def dec_chunks(s):
'''Split a chunk into strings or sub-chunks'''
i = 0
result = []
while i < len(s):
size = dec_long(s[i : i + 4])
i += 4
result.append(s[i : i + size])
i += size
return result
# Point and signature data
def enc_point(p):
'''Encode a point p = (x, y)'''
x, y = p
sx = enc_long(x)
sy = enc_long(y)
diff = len(sx) - len(sy)
if diff > 0:
sy = '\x00' * diff + sy
elif diff < 0:
sx = '\x00' * -diff + sx
return sx + sy
def dec_point(s):
'''Decode an even length string s to a point(x, y)'''
d = len(s) / 2
return (dec_long(s[:d]), dec_long(s[d:]))
class Encoder:
def __init__(self):
self._io = StringIO.StringIO()
def int(self, n, size = 4):
self._io.write(enc_fixed_long(n, size))
return self
def long(self, n, pre = 2):
lstr = enc_long(n)
self._io.write(enc_fixed_long(len(lstr), pre) + lstr)
return self
def str(self, s, pre = 2):
self._io.write(enc_fixed_long(len(s), pre) + s)
return self
def point(self, p, pre = 2):
lstr = enc_point(p)
self._io.write(enc_fixed_long(len(lstr), pre) + lstr)
return self
def chunk(self, enc, pre = 2):
lstr = enc.out()
self._io.write(enc_fixed_long(len(lstr), pre) + lstr)
return self
def out(self):
return self._io.getvalue()
class Decoder:
def __init__(self, data, offset = 0):
self._io = StringIO.StringIO(data)
self._io.seek(offset)
self._res = []
self._limit = None
self._parent = None
def _ret(self):
## if self._parent and self._io.tell() >= self._limit:
## return self.exit()
## else:
## return self
return self
def int(self, size = 4):
self._res.append(dec_long(self._io.read(size)))
return self._ret()
def long(self, pre = 2):
llen = dec_long(self._io.read(pre))
self._res.append(dec_long(self._io.read(llen)))
return self._ret()
def str(self, pre = 2):
llen = dec_long(self._io.read(pre))
self._res.append(self._io.read(llen))
return self._ret()
def point(self, pre = 2):
llen = dec_long(self._io.read(pre))
self._res.append(dec_point(self._io.read(llen)))
return self._ret()
def enter(self, pre = 2):
llen = dec_long(self._io.read(pre))
subcoder = Decoder("")
subcoder._io = self._io
subcoder._parent = self
subcoder._limit = self._io.tell() + llen
return subcoder
def chunk(self, pre = 2):
llen = dec_long(self._io.read(pre))
self._res.append(Decoder(self._io.read(llen)))
return self._ret()
def exit(self):
if self._parent:
self._parent._io.seek(self._limit)
self._parent._res.append(self._res)
return self._parent
else:
raise RuntimeError, "Cannont exit top level Decoder"
def continues(self):
return (not self._limit) or (self._io.tell() < self._limit)
def out(self, exit_all = False):
if exit_all and self._parent:
return self.exit().out()
else:
r = self._res
self._res = []
return r
def only(self):
if self._res:
return self._res.pop(0)
else:
return RuntimeError, "Only what? (Empty decoder stack)"