sshpubkeys/keys.py
def _process_ssh_dss(self, data):
        """Parses ssh-dsa public keys."""
        data_fields = {}
        current_position = 0
        for item in ("p", "q", "g", "y"):
            current_position, value = self._unpack_by_int(data, current_position)
            data_fields[item] = self._parse_long(value)

        q_bits = self._bits_in_number(data_fields["q"])
        p_bits = self._bits_in_number(data_fields["p"])
        if q_bits != self.DSA_N_LENGTH:
            raise InvalidKeyError("Incorrect DSA key parameters: bits(p)=%s, q=%s" % (self.bits, q_bits))
        if self.strict_mode:
            min_length = self.DSA_MIN_LENGTH_STRICT
            max_length = self.DSA_MAX_LENGTH_STRICT
        else:
            min_length = self.DSA_MIN_LENGTH_LOOSE
            max_length = self.DSA_MAX_LENGTH_LOOSE
        if p_bits < min_length:
            raise TooShortKeyError("%s key can not be shorter than %s bits (was %s)" % (self.key_type, min_length, p_bits))
        if p_bits > max_length:
            raise TooLongKeyError(
                "%s key data can not be longer than %s bits (was %s)" % (self.key_type, max_length, p_bits)
            )

        dsa_parameters = DSAParameterNumbers(data_fields["p"], data_fields["q"], data_fields["g"])
        self.dsa = DSAPublicNumbers(data_fields["y"], dsa_parameters).public_key(default_backend())
        self.bits = self.dsa.key_size

        return current_position
def _process_ssh_dss(self, data):
        data_fields = {}
        current_position = 0
        for item in ("p", "q", "g", "y"):
            current_position, value = self._unpack_by_int(data, current_position)
            data_fields[item] = self._parse_long(value)

        q_bits = self._bits_in_number(data_fields["q"])
        p_bits = self._bits_in_number(data_fields["p"])
        if q_bits != self.DSA_N_LENGTH:
            raise InvalidKeyError("Incorrect DSA key parameters: bits(p)=%s, q=%s" % (self.bits, q_bits))
        if self.strict_mode:
            min_length = self.DSA_MIN_LENGTH_STRICT
            max_length = self.DSA_MAX_LENGTH_STRICT
        else:
            min_length = self.DSA_MIN_LENGTH_LOOSE
            max_length = self.DSA_MAX_LENGTH_LOOSE
        if p_bits < min_length:
            raise TooShortKeyError("%s key can not be shorter than %s bits (was %s)" % (self.key_type, min_length, p_bits))
        if p_bits > max_length:
            raise TooLongKeyError(
                "%s key data can not be longer than %s bits (was %s)" % (self.key_type, max_length, p_bits)
            )

        dsa_parameters = DSAParameterNumbers(data_fields["p"], data_fields["q"], data_fields["g"])
        self.dsa = DSAPublicNumbers(data_fields["y"], dsa_parameters).public_key(default_backend())
        self.bits = self.dsa.key_size

        return current_position
def _process_ssh_dss ( self , data ) : data_fields = { } current_position = 0 for item in ( "p" , "q" , "g" , "y" ) : current_position , value = self . _unpack_by_int ( data , current_position ) data_fields [ item ] = self . _parse_long ( value ) q_bits = self . _bits_in_number ( data_fields [ "q" ] ) p_bits = self . _bits_in_number ( data_fields [ "p" ] ) if q_bits != self . DSA_N_LENGTH : raise InvalidKeyError ( "Incorrect DSA key parameters: bits(p)=%s, q=%s" % ( self . bits , q_bits ) ) if self . strict_mode : min_length = self . DSA_MIN_LENGTH_STRICT max_length = self . DSA_MAX_LENGTH_STRICT else : min_length = self . DSA_MIN_LENGTH_LOOSE max_length = self . DSA_MAX_LENGTH_LOOSE if p_bits < min_length : raise TooShortKeyError ( "%s key can not be shorter than %s bits (was %s)" % ( self . key_type , min_length , p_bits ) ) if p_bits > max_length : raise TooLongKeyError ( "%s key data can not be longer than %s bits (was %s)" % ( self . key_type , max_length , p_bits ) ) dsa_parameters = DSAParameterNumbers ( data_fields [ "p" ] , data_fields [ "q" ] , data_fields [ "g" ] ) self . dsa = DSAPublicNumbers ( data_fields [ "y" ] , dsa_parameters ) . public_key ( default_backend ( ) ) self . bits = self . dsa . key_size return current_position
Parses ssh-dsa public keys.
Parses ssh - dsa public keys .