コード例 #1
0
 def __init__(
     self,
     decode: Arg(metavar='decode-as',
                 type=str,
                 help='Input encoding; Guess encoding by default.') = None,
     encode: Arg(metavar='encode-as',
                 type=str,
                 help=F'Output encoding; The default is {Unit.codec}.'
                 ) = Unit.codec,
     decerr: Arg.Option(
         '-d',
         choices=Handler,
         help='Specify an error handler for decoding.') = None,
     encerr: Arg.Option(
         '-e',
         choices=Handler,
         help='Specify an error handler for encoding.') = None,
     errors: Arg.Option(
         '-E',
         choices=Handler,
         help=('Specify an error handler for both encoding and decoding. '
               'The possible choices are the following: {choices}')) = None,
 ):
     super().__init__(decode=decode,
                      encode=encode,
                      decerr=Arg.AsOption(decerr or errors or 'STRICT',
                                          Handler).value,
                      encerr=Arg.AsOption(encerr or errors or 'STRICT',
                                          Handler).value)
コード例 #2
0
 def __init__(
     self,
     public: Arg.Switch(
         '-p', help='Force public key output even if the input is private.'
     ) = False,
     output: Arg(
         help=
         'Select an output format (PEM/DER/XKMS/TEXT/JSON), default is PEM.'
     ) = RSAFormat.PEM):
     super().__init__(public=public, output=Arg.AsOption(output, RSAFormat))
コード例 #3
0
ファイル: __init__.py プロジェクト: binref/refinery
    def __init__(
            self,
            encode: Arg.
        Option(
            '-e',
            group='BIN',
            choices=UNIT,
            help=
            ('Select an encoder unit used to represent binary data in the JSON output. Available are: {choices}.'
             )) = None,
            digest: Arg.
        Option(
            '-d',
            group='BIN',
            choices=HASH,
            help=
            ('Select a hashing algorithm to digest binary data; instead of the data, only the hash will be displayed. The '
             'available algorithms are: {choices}.')) = None,
            **keywords):
        encode = Arg.AsOption(encode, UNIT)
        digest = Arg.AsOption(digest, HASH)

        super().__init__(**keywords)

        if encode is not None and digest is not None:
            raise ValueError(
                'Only one binary data conversion can be specified.')
        elif encode is not None:
            unit = encode.value()

            class CustomEncoder(DotNetEncoder):  # noqa
                def encode_bytes(self, obj):
                    return unit.reverse(obj).decode('utf8')
        elif digest is not None:

            class CustomEncoder(DotNetEncoder):
                def encode_bytes(self, obj):
                    return digest(obj).hexdigest()
        else:
            CustomEncoder = DotNetEncoder

        self.encoder = CustomEncoder
コード例 #4
0
 def __init__(
     self,
     parts: Arg(
         'parts',
         nargs='?',
         type=str,
         help=
         ('A string containing any ordering of the letters R, G, B, and A (case-insensitive). '
          'These pixel components will be extracted from every pixel in the given order. The '
          'default value is {default}.')) = 'RGB'):
     super().__init__(parts=tuple(
         Arg.AsOption(p, PIXEL_PART) for p in parts))
コード例 #5
0
ファイル: rsa.py プロジェクト: binref/refinery
    def __init__(
        self,
        key: Arg(help='RSA key in PEM, DER, or Microsoft BLOB format.'),
        swapkeys: Arg.Switch('-s',
                             help='Swap public and private exponent.') = False,
        textbook: Arg.Switch('-t',
                             group='PAD',
                             help='Equivalent to --padding=NONE.') = False,
        padding: Arg.Option(
            '-p',
            group='PAD',
            choices=PAD,
            help=
            'Choose one of the following padding modes: {choices}. The default is AUTO.'
        ) = PAD.AUTO,
        rsautl: Arg.Switch(
            '-r',
            group='PAD',
            help=
            'Act as rsautl from OpenSSH; This is equivalent to --swapkeys --padding=PKCS10'
        ) = False,
    ):
        padding = Arg.AsOption(padding, PAD)
        if textbook:
            if padding != PAD.AUTO:
                raise ValueError('Conflicting padding options!')
            padding = padding.NONE
        if rsautl:
            if padding and padding != PAD.PKCS10:
                raise ValueError('Conflicting padding options!')
            swapkeys = True
            padding = PAD.PKCS10

        super().__init__(key=key,
                         textbook=textbook,
                         padding=padding,
                         swapkeys=swapkeys)

        self._key_hash = None
        self._key_data = None
コード例 #6
0
ファイル: __init__.py プロジェクト: binref/refinery
 def __init__(
         self,
         size: Arg(help='The number of bytes to generate.', type=number),
         salt: Arg(help='Salt for the derivation.'),
         hash: Arg.
     Option(
         choices=HASH,
         metavar='hash',
         help=
         'Specify one of these algorithms (default is {default}): {choices}'
     ) = None,
         iter: Arg.Number(
             metavar='iter',
             help='Number of iterations; default is {default}.') = None,
         **kw):
     if hash is not None:
         name = Arg.AsOption(hash, HASH)
         hash = importlib.import_module(F'Crypto.Hash.{name}')
     return super().__init__(salt=salt,
                             size=size,
                             iter=iter,
                             hash=hash,
                             **kw)