(version,stream,ripe)
| 121 | return sha2.digest()[0:32] |
| 122 | |
| 123 | def encodeAddress(version,stream,ripe): |
| 124 | if version >= 2 and version < 4: |
| 125 | if len(ripe) != 20: |
| 126 | raise Exception("Programming error in encodeAddress: The length of a given ripe hash was not 20.") |
| 127 | if ripe[:2] == '\x00\x00': |
| 128 | ripe = ripe[2:] |
| 129 | elif ripe[:1] == '\x00': |
| 130 | ripe = ripe[1:] |
| 131 | elif version == 4: |
| 132 | if len(ripe) != 20: |
| 133 | raise Exception("Programming error in encodeAddress: The length of a given ripe hash was not 20.") |
| 134 | ripe = ripe.lstrip('\x00') |
| 135 | |
| 136 | storedBinaryData = encodeVarint(version) + encodeVarint(stream) + ripe |
| 137 | |
| 138 | # Generate the checksum |
| 139 | sha = hashlib.new('sha512') |
| 140 | sha.update(storedBinaryData) |
| 141 | currentHash = sha.digest() |
| 142 | sha = hashlib.new('sha512') |
| 143 | sha.update(currentHash) |
| 144 | checksum = sha.digest()[0:4] |
| 145 | |
| 146 | asInt = int(hexlify(storedBinaryData) + hexlify(checksum),16) |
| 147 | return 'BM-'+ encodeBase58(asInt) |
| 148 | |
| 149 | def decodeAddress(address): |
| 150 | #returns (status, address version number, stream number, data (almost certainly a ripe hash)) |
no test coverage detected