Browse Source

little refactoring

pull/16/head
R4SAS 6 years ago
parent
commit
70f386193a
  1. 8
      pbincli/actions.py
  2. 20
      pbincli/format.py

8
pbincli/actions.py

@ -53,7 +53,7 @@ def send(args, api_client):
if args.debug: print("Response:\t{}\n".format(result)) if args.debug: print("Response:\t{}\n".format(result))
if 'status' in result and not result['status']: if result['status'] == 0:
passphrase = paste.getHash() passphrase = paste.getHash()
print("Paste uploaded!\nPasteID:\t{}\nPassword:\t{}\nDelete token:\t{}\n\nLink:\t\t{}?{}#{}".format( 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, api_client.server,
result['id'], result['id'],
passphrase)) passphrase))
elif 'status' in result and result['status']: elif result['status']:
print("Something went wrong...\nError:\t\t{}".format(result['message'])) print("Something went wrong...\nError:\t\t{}".format(result['message']))
exit(1) exit(1)
else: else:
@ -96,7 +96,7 @@ def get(args, api_client):
if args.debug: print("Response:\t{}\n".format(result)) if args.debug: print("Response:\t{}\n".format(result))
if 'status' in result and not result['status']: if result['status'] == 0:
print("Paste received!") print("Paste received!")
version = result['v'] if 'v' in result else 1 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...") print("Burn afrer reading flag found. Deleting paste...")
api_client.delete(json_encode({'pasteid':pasteid,'deletetoken':'burnafterreading'})) 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'])) print("Something went wrong...\nError:\t\t{}".format(result['message']))
exit(1) exit(1)
else: else:

20
pbincli/format.py

@ -129,35 +129,33 @@ class Paste:
def __decompress(self, s): def __decompress(self, s):
if self._version == 2: if self._version == 2 and self._compression == 'zlib':
if self._compression == 'zlib':
# decompress data # decompress data
return zlib.decompress(s, -zlib.MAX_WBITS) return zlib.decompress(s, -zlib.MAX_WBITS)
elif self._compression == 'none': elif self._version == 2 and self._compression == 'none':
# nothing to do, just return original data # nothing to do, just return original data
return s return s
elif self._version == 1:
return zlib.decompress(bytearray(map(ord, b64decode(s.encode('utf-8')).decode('utf-8'))), -zlib.MAX_WBITS)
else: else:
raise PBinCLIException('Unknown compression type provided in paste!') raise PBinCLIException('Unknown compression type provided in paste!')
else:
return zlib.decompress(bytearray(map(ord, b64decode(s.encode('utf-8')).decode('utf-8'))), -zlib.MAX_WBITS)
def __compress(self, s): def __compress(self, s):
if self._version == 2: if self._version == 2 and self._compression == 'zlib':
if self._compression == 'zlib':
# using compressobj as compress doesn't let us specify wbits # using compressobj as compress doesn't let us specify wbits
# needed to get the raw stream without headers # needed to get the raw stream without headers
co = zlib.compressobj(wbits=-zlib.MAX_WBITS) co = zlib.compressobj(wbits=-zlib.MAX_WBITS)
return co.compress(s) + co.flush() return co.compress(s) + co.flush()
elif self._compression == 'none': elif self._version == 2 and self._compression == 'none':
# nothing to do, just return original data # nothing to do, just return original data
return s return s
else: elif self._version == 1:
raise PBinCLIException('Unknown compression type provided!')
else:
co = zlib.compressobj(wbits=-zlib.MAX_WBITS) co = zlib.compressobj(wbits=-zlib.MAX_WBITS)
b = co.compress(s) + co.flush() b = co.compress(s) + co.flush()
return b64encode(''.join(map(chr, b)).encode('utf-8')) return b64encode(''.join(map(chr, b)).encode('utf-8'))
else:
raise PBinCLIException('Unknown compression type provided!')
def decrypt(self): def decrypt(self):

Loading…
Cancel
Save