Compare commits

...

3 Commits

Author SHA1 Message Date
jebcoat 01d3d881b1
changed default expire value (#43) 4 months ago
Benjamin Renard 869cf130a4 Fix pycryptodome support when pycrypto is not available 4 months ago
Benjamin Renard b40f48295a Add CLI autocompletion using argcomplete 4 months ago
  1. 8
      pbincli/cli.py
  2. 17
      pbincli/format.py
  3. 1
      requirements.txt

8
pbincli/cli.py

@ -1,7 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
# PYTHON_ARGCOMPLETE_OK
import os, sys, argparse import os, sys, argparse
from distutils.util import strtobool from distutils.util import strtobool
import argcomplete
import pbincli.actions import pbincli.actions
from pbincli.api import PrivateBin from pbincli.api import PrivateBin
from pbincli.utils import PBinCLIException, PBinCLIError, validate_url_ending from pbincli.utils import PBinCLIException, PBinCLIError, validate_url_ending
@ -46,7 +49,7 @@ def main():
send_parser.add_argument("-t", "--text", help="Text in quotes. Ignored if used stdin. If not used, forcefully used stdin") send_parser.add_argument("-t", "--text", help="Text in quotes. Ignored if used stdin. If not used, forcefully used stdin")
send_parser.add_argument("-f", "--file", help="Example: image.jpg or full path to file") send_parser.add_argument("-f", "--file", help="Example: image.jpg or full path to file")
send_parser.add_argument("-p", "--password", help="Password for encrypting paste") send_parser.add_argument("-p", "--password", help="Password for encrypting paste")
send_parser.add_argument("-E", "--expire", default="1day", action="store", send_parser.add_argument("-E", "--expire", default=argparse.SUPPRESS, action="store",
choices=["5min", "10min", "1hour", "1day", "1week", "1month", "1year", "never"], help="Paste lifetime (default: 1day)") choices=["5min", "10min", "1hour", "1day", "1week", "1month", "1year", "never"], help="Paste lifetime (default: 1day)")
send_parser.add_argument("-B", "--burn", default=argparse.SUPPRESS, action="store_true", help="Set \"Burn after reading\" flag") send_parser.add_argument("-B", "--burn", default=argparse.SUPPRESS, action="store_true", help="Set \"Burn after reading\" flag")
send_parser.add_argument("-D", "--discus", default=argparse.SUPPRESS, action="store_true", help="Open discussion for sent paste") send_parser.add_argument("-D", "--discus", default=argparse.SUPPRESS, action="store_true", help="Open discussion for sent paste")
@ -124,6 +127,9 @@ def main():
delete_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output") delete_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output")
delete_parser.set_defaults(func=pbincli.actions.delete) delete_parser.set_defaults(func=pbincli.actions.delete)
# Add argcomplete trigger
argcomplete.autocomplete(parser)
# parse arguments # parse arguments
args = parser.parse_args() args = parser.parse_args()

17
pbincli/format.py

@ -20,7 +20,11 @@ try:
else: else:
from Crypto.Random import get_random_bytes from Crypto.Random import get_random_bytes
except ImportError: except ImportError:
PBinCLIError("Unable import pycryptodome") try:
from Cryptodome.Cipher import AES
from Cryptodome.Random import get_random_bytes
except ImportError:
PBinCLIError("Unable import pycryptodome")
CIPHER_ITERATION_COUNT = 100000 CIPHER_ITERATION_COUNT = 100000
@ -120,8 +124,15 @@ class Paste:
def __deriveKey(self, salt): def __deriveKey(self, salt):
from Crypto.Protocol.KDF import PBKDF2 try:
from Crypto.Hash import HMAC, SHA256 from Crypto.Protocol.KDF import PBKDF2
from Crypto.Hash import HMAC, SHA256
except ModuleNotFoundError:
try:
from Cryptodome.Protocol.KDF import PBKDF2
from Cryptodome.Hash import HMAC, SHA256
except ImportError:
PBinCLIError("Unable import pycryptodome")
# Key derivation, using PBKDF2 and SHA256 HMAC # Key derivation, using PBKDF2 and SHA256 HMAC
return PBKDF2( return PBKDF2(

1
requirements.txt

@ -2,3 +2,4 @@ pycryptodome
sjcl sjcl
base58 base58
requests requests
argcomplete

Loading…
Cancel
Save