diff --git a/pbincli/actions.py b/pbincli/actions.py index 3966442..892e27d 100644 --- a/pbincli/actions.py +++ b/pbincli/actions.py @@ -53,7 +53,7 @@ def send(args, api_client): if args.debug: print("Response:\t{}\n".format(result)) - if 'status' in result and not result['status']: + if result['status'] == 0: passphrase = paste.getHash() print("Paste uploaded!\nPasteID:\t{}\nPassword:\t{}\nDelete token:\t{}\n\nLink:\t\t{}?{}#{}".format( @@ -63,7 +63,7 @@ def send(args, api_client): api_client.server, result['id'], passphrase)) - elif 'status' in result and result['status']: + elif result['status']: print("Something went wrong...\nError:\t\t{}".format(result['message'])) exit(1) else: @@ -96,7 +96,7 @@ def get(args, api_client): if args.debug: print("Response:\t{}\n".format(result)) - if 'status' in result and not result['status']: + if result['status'] == 0: print("Paste received!") version = result['v'] if 'v' in result else 1 @@ -137,7 +137,7 @@ def get(args, api_client): print("Burn afrer reading flag found. Deleting paste...") api_client.delete(json_encode({'pasteid':pasteid,'deletetoken':'burnafterreading'})) - elif 'status' in result and result['status']: + elif result['status']: print("Something went wrong...\nError:\t\t{}".format(result['message'])) exit(1) else: diff --git a/pbincli/format.py b/pbincli/format.py index c21ce57..fc7b108 100644 --- a/pbincli/format.py +++ b/pbincli/format.py @@ -129,35 +129,33 @@ class Paste: def __decompress(self, s): - if self._version == 2: - if self._compression == 'zlib': - # decompress data - return zlib.decompress(s, -zlib.MAX_WBITS) - elif self._compression == 'none': - # nothing to do, just return original data - return s - else: - raise PBinCLIException('Unknown compression type provided in paste!') - else: + if self._version == 2 and self._compression == 'zlib': + # decompress data + return zlib.decompress(s, -zlib.MAX_WBITS) + elif self._version == 2 and self._compression == 'none': + # nothing to do, just return original data + return s + elif self._version == 1: return zlib.decompress(bytearray(map(ord, b64decode(s.encode('utf-8')).decode('utf-8'))), -zlib.MAX_WBITS) + else: + raise PBinCLIException('Unknown compression type provided in paste!') def __compress(self, s): - if self._version == 2: - if self._compression == 'zlib': - # using compressobj as compress doesn't let us specify wbits - # needed to get the raw stream without headers - co = zlib.compressobj(wbits=-zlib.MAX_WBITS) - return co.compress(s) + co.flush() - elif self._compression == 'none': - # nothing to do, just return original data - return s - else: - raise PBinCLIException('Unknown compression type provided!') - else: + if self._version == 2 and self._compression == 'zlib': + # using compressobj as compress doesn't let us specify wbits + # needed to get the raw stream without headers + co = zlib.compressobj(wbits=-zlib.MAX_WBITS) + return co.compress(s) + co.flush() + elif self._version == 2 and self._compression == 'none': + # nothing to do, just return original data + return s + elif self._version == 1: co = zlib.compressobj(wbits=-zlib.MAX_WBITS) b = co.compress(s) + co.flush() return b64encode(''.join(map(chr, b)).encode('utf-8')) + else: + raise PBinCLIException('Unknown compression type provided!') def decrypt(self):