Validate the given key
501762
def validate_key(request, group=None, perm=None, keytype=None):
    
    def update_last_access():
        if KEY_LAST_USED_UPDATE:
            request.key.save()
    
    if request.user.is_authenticated() and is_valid_consumer(request):
        if not group and not perm and not keytype:
            return update_last_access()
        elif keytype:
            if request.key.is_type( keytype ):
                return update_last_access()
        elif group:
            if request.key.belongs_to_group( group ):
                return update_last_access()
        elif perm:
            if request.key.has_perm( perm ):
                return update_last_access()
        raise AccessForbidden
    raise AccessUnauthorized
1243026
private function validateKey($key)
    {
        $details = openssl_pkey_get_details($key);

        if (!isset($details['key']) || $details['type'] !== OPENSSL_KEYTYPE_RSA) {
            throw new \InvalidArgumentException('This key is not compatible with RSA signatures');
        }
    }
936166
def check_key!(key)
      return if key.is_a?(String) || key.is_a?(Symbol)
      raise TypeError, 'key must be a String or Symbol'
    end
529515
public void setKey(String key) {
        Validate.notNull(key);
        key = key.trim();
        Validate.notEmpty(key); // trimming could potentially make empty, so validate here
        if (parent != null) {
            int i = parent.indexOfKey(this.key);
            if (i != Attributes.NotFound)
                parent.keys[i] = key;
        }
        this.key = key;
    }
1078004
protected function validateKey(/*# string */ &$key)
    {
        // validate key
        if (is_string($key)) {
            $key = trim($key);
            return;
        }

        // throw exception
        throw new InvalidArgumentException(
            Message::get(Message::CACHE_INVALID_KEY, $key),
            Message::CACHE_INVALID_KEY
        );
    }
1140213
public static function validate($code = '', $key = -1)
    {
        if (strlen($key) < 1) {
            return false;
        }

        if (!is_numeric($key)) {
            return false;
        }

        if (!is_string($code)) {
            return false;
        }

        if (strlen($code) < 2) {
            return false;
        }

        $numerals = str_split($code);
        $rank = array_reverse(array_keys($numerals));
        $orderedNumerals = array();
        foreach ($rank as $i => $rankValue) {
            $orderedNumerals[$rankValue + 1] = $numerals[$i];
        }
        $results = array();
        foreach ($orderedNumerals as $cle => $value) {
            $results[$value] = ($cle % 2 == 0) ? ((int) $value * 1) : ((int) $value * 2);
        }
        $sum = 0;
        foreach ($results as $cle => $value) {
            $sum += array_sum(str_split($value));
        }
        $validKey = str_split($sum);
        $validKey = 10 - array_pop($validKey);

        return $key === $validKey;
    }
400995
def validate_key(key)
      unless key.is_a?(Symbol) || key.is_a?(String)
        raise ArgumentError, 'Key must be a string or symbol'
      end
      key
    end
431211
private void validateEntry(String key, Object value) {
        if (isBlank(key)) {
            throw new IllegalArgumentException("key cannot be null/blank");
        }
        if (ModifiedUTF8Charset.calculateByteLength(key) > 255) {
            throw new IllegalArgumentException("key length > 255 bytes");
        }
        else if (value == null) {
            throw new IllegalArgumentException("value cannot be null");
        }
        else if (value instanceof String) {
            if (ModifiedUTF8Charset.calculateByteLength((String) value) > 32767) {
                throw new IllegalArgumentException("string value length > 34767 bytes");
            }
        }
        else if (value instanceof Integer ||
                 value instanceof Long ||
                 value instanceof Double) {
            // valid
        } else {
            throw new IllegalArgumentException("Illegal value type: "+value.getClass().toString());
        }
    }
964042
function validateArray(node, schema, key) {
    if (Array.isArray(node)) {
      if (schema[SCHEMALENGTH]) {
        checkLength(node.length, schema, key);
      }
      for (var arrayI = 0; arrayI < node.length; arrayI++) {
        try {
          validateNode(node[arrayI], schema[SCHEMADATA], "");
        } catch (e) {
          throw new ValidationException(
            e.message + key + " position " + arrayI
          );
        }
      }
    } else {
      throw new ValidationException("Expected array for " + key);
    }
  }
459658
public function validateKey($key)
    {
        $length = strlen((string) $key);

        if (!$length) {
            $this->addError('key', 'Key cannot be empty');
            return false;
        }

        return true;
    }
757120
def _check_valid_key(self, key):
        
        if not isinstance(key, key_type) and key is not None:
            raise ValueError('%r is not a valid key type' % key)
        if not VALID_KEY_RE_EXTENDED.match(key) or key == u'/':
            raise ValueError('%r contains illegal characters' % key)
425363
def validate_config(key: str, config: dict) -> None:
    

    try:
        jsonschema.validate(config, CONFIG_JSON_SCHEMA[key])
    except jsonschema.ValidationError as x_validation:
        raise JSONValidation('JSON validation error on {} configuration: {}'.format(key, x_validation.message))
    except jsonschema.SchemaError as x_schema:
        raise JSONValidation('JSON schema error on {} specification: {}'.format(key, x_schema.message))
225299
protected function validateKey($key)
    {
        if (!is_string($key)) {
            throw new CacheKeyException("Cache key must be a string, " . gettype($key) . " given");
        }

        if (preg_match("/[^A-Za-z0-9\._-]/", $key)) {
            throw new CacheKeyException("Cache key contains invalid characters: {$key}");
        }

        if (strlen($key) > 64) {
            throw new CacheKeyException("Cache key cannot be longer than 64 characters: {$key}");
        }
    }
804633
def check_key(self, key):
        
        if self.key_size and len(key) not in self.key_size:
            raise TypeError('invalid key size %s, must be one of %s' %
                            (len(key), self.key_size))
477095
private static boolean validateKey(String key) {
    if (key.length() > KEY_MAX_SIZE
        || key.isEmpty()
        || key.charAt(0) < 'a'
        || key.charAt(0) > 'z') {
      return false;
    }
    for (int i = 1; i < key.length(); i++) {
      char c = key.charAt(i);
      if (!(c >= 'a' && c <= 'z')
          && !(c >= '0' && c <= '9')
          && c != '_'
          && c != '-'
          && c != '*'
          && c != '/') {
        return false;
      }
    }
    return true;
  }
1153895
private function validateKey(string $key): void
    {
        $key_pattern = $this->cache->getOptions()->getKeyPattern();

        if ($key === '') {
            throw new InvalidKeyException('An empty key is not allowed');
        } elseif (!empty($key_pattern && !preg_match($key_pattern, $key))) {
            throw new InvalidKeyException(
                sprintf('The key "%s" does not match against pattern "%s"', $key, $key_pattern)
            );
        }
    }
65106
function validate(cmd, args, info) {
  AbstractCommand.prototype.validate.apply(this, arguments);
  var index = parseInt(args[1])
    , value = info.db.getKey(args[0], info);
  if(value === undefined) {
    throw NoSuchKey;
  }else if(isNaN(index) || (index < 0 || index >= value.getLength())) {
    throw IndexRange;
  }
  args[1] = index;
}