Input validation for YHSM_YubiKeySecret or string.
540599
def input_validate_yubikey_secret(data, name='data'):
    
    if isinstance(data, pyhsm.aead_cmd.YHSM_YubiKeySecret):
        data = data.pack()
    return input_validate_str(data, name)
564898
def input_validate_nonce(nonce, name='nonce', pad = False):
    
    if type(nonce) is not str:
        raise pyhsm.exception.YHSM_WrongInputType( \
            name, str, type(nonce))
    if len(nonce) > pyhsm.defines.YSM_AEAD_NONCE_SIZE:
        raise pyhsm.exception.YHSM_InputTooLong(
            name, pyhsm.defines.YSM_AEAD_NONCE_SIZE, len(nonce))
    if pad:
        return nonce.ljust(pyhsm.defines.YSM_AEAD_NONCE_SIZE, chr(0x0))
    else:
        return nonce
733699
def validate(self, key, value):
    """"""
    if self._validator is not None:
      self._validator(key, value)
361147
def validate_key(key: str):
        
        if "//" in key:
            raise DoubleSlashKeyError(key)
        elif normpath(key) != key:
            raise NonNormalisedKeyError(key)
848142
def validate_input(self):
        """"""
        if self.vert[1] <= self.vert[0]:
            raise ValueError(u'{} must be larger than {}'.format(self.vert[1], self.vert[0]))
934434
def valid_input?(input)
      case @attributes[:type]
      when :boolean
        [true,false].include?(input)
      when :enum
        raise MissingValuesError unless @attributes[:values]
        raise InvalidValuesError unless @attributes[:values].class == Array
        @attributes[:values].include?(input)
      when :string
        format = @attributes[:format] || :anything
        Validator.valid_input?(format, input)
      when :number
        [Integer, Fixnum].include?(input.class)
      when :timestamp
        # TODO timestamp pending
        # raise PendingBranchError
        true
      else
        false
      end
    end
1345573
def _validate_boolean(self, input_boolean, path_to_root, object_title=''):

        '''
            
        '''

        rules_path_to_root = re.sub('\[\d+\]', '[0]', path_to_root)
        input_criteria = self.keyMap[rules_path_to_root]
        error_dict = {
            'object_title': object_title,
            'model_schema': self.schema,
            'input_criteria': input_criteria,
            'failed_test': 'value_datatype',
            'input_path': path_to_root,
            'error_value': input_boolean,
            'error_code': 4001
        }
        if 'equal_to' in input_criteria.keys():
            if input_boolean != input_criteria['equal_to']:
                error_dict['failed_test'] = 'equal_to'
                error_dict['error_code'] = 4026
                raise InputValidationError(error_dict)

    # TODO: validate boolean against identical to reference

    # TODO: run lambda function and call validation url

        return input_boolean
820375
def match_keys
      values.each do |v|
        Textoken.expression_err("#{v}: is not permitted.") unless yaml.key?(v)
        add_regexps(yaml[v])
      end
    end
1117571
def validatepubkey(pub):
    '''
    
    '''

    try:
        pub = hexstrlify(unhexlify(pub))
    except:
        return False
    if len(pub) == 130:
        if pub[:2] != '04':
            return False
        if uncompress(compress(pub)) != pub:
            return False
    elif len(pub) == 66:
        if pub[:2] != '02' and pub[:2] != '03':
            return False
    else:
        return False
    return pub
727221
def validate_iso_date key, value, opts
      if opts[:iso_date]
        return value.strftime("%Y-%m-%d")  if value.respond_to?(:strftime)
      end
      value
    end
208137
def check_key(self, key):
        """"""
        return _check_key(key, allow_unicode_keys=self.allow_unicode_keys,
                          key_prefix=self.key_prefix)
63916
def validate_appname_or_none(option, value):
    """"""
    if value is None:
        return value
    validate_string(option, value)
    # We need length in bytes, so encode utf8 first.
    if len(value.encode('utf-8')) > 128:
        raise ValueError("%s must be <= 128 bytes" % (option,))
    return value
746132
def validate(self, value):
        
        if not isinstance(value, (str, unicode)):
            raise orb.errors.ColumnValidationError(self, 'Invalid password.')

        elif not self.__allowUnicode and value != projex.text.toAscii(value):
            raise orb.errors.ColumnValidationError(self, 'Only ASCII characters are allowed for your password.')

        elif len(value) < self.__minlength or \
                (self.__requireUppercase and not re.search('[A-Z]', value)) or \
                (self.__requireLowercase and not re.search('[a-z]', value)) or \
                (self.__requireNumber and not re.search('[0-9]', value)) or \
                (self.__requireWildcard and not re.search('[^a-zA-Z0-9]', value)):
            raise orb.errors.ColumnValidationError(self, self.rules())

        # check for invalid characters
        elif self.__invalidCharacters and re.search(self.__invalidCharacters, value):
            raise orb.errors.ColumnValidationError(self, self.__invalidCharactersRule)

        else:
            return super(PasswordColumn, self).validate(value)
1100596
def is_valid_key(key):
    

    if PY3 and isinstance(key, bytes):
        raise TypeError("needs to be str not bytes")

    for c in key:
        if c < " " or c > "}" or c == "=":
            return False
    else:
        return bool(key)
413433
def _validateAttrs(self, keys):
        """"""
        badAttrsMsg = ""
        for k in keys:
            if k not in self.attrs:
                badAttrsMsg += "Attribute key '%s' is not a valid attribute"%(k)
        if badAttrsMsg:
            raise ValueError("Encountered invalid attributes.  ALLOWED: %s%s%s"\
                %(list(self.attrs), os.linesep, badAttrsMsg))
208699
def _is_valid_dkim(self, value):
        """"""
        validator_dict = {'h': lambda val: val in ['sha1', 'sha256'],
                          's': lambda val: val in ['*', 'email'],
                          't': lambda val: val in ['y', 's'],
                          'v': lambda val: val == 'DKIM1',
                          'k': lambda val: val == 'rsa',
                          'n': lambda _: True,
                          'g': lambda _: True}

        splitted = value.split('\\;')
        found_key = False
        for splitted_value in splitted:
            sub_split = map(lambda x: x.strip(), splitted_value.split("=", 1))
            if len(sub_split) < 2:
                return False
            key, value = sub_split[0], sub_split[1]
            if key == "p":
                is_valid_key = self._is_valid_dkim_key(value)
                if not is_valid_key:
                    return False
                found_key = True
            else:
                is_valid_key = validator_dict.get(key, lambda _: False)(value)
                if not is_valid_key:
                    return False
        return found_key
969408
def filter_yn(string, default=None):
    """"""
    if string.startswith(('Y', 'y')):
        return True
    elif string.startswith(('N', 'n')):
        return False
    elif not string and default is not None:
        return True if default else False
    raise InvalidInputError