A helper function for creating signature.
Return the signature on success.
Return error code if parameter is not valid.
7392
private static function createSignature(
            $appId, $secretId, $secretKey, $expiration, $bucket, $fileId) {
        if (empty($secretId) || empty($secretKey)) {
            return self::AUTH_SECRET_ID_KEY_ERROR;
        }

        $now = time();
        $random = rand();
        $plainText = "a=$appId&k=$secretId&e=$expiration&t=$now&r=$random&f=$fileId&b=$bucket";
        $bin = hash_hmac('SHA1', $plainText, $secretKey, true);
        $bin = $bin.$plainText;

        $signature = base64_encode($bin);

        return $signature;
    }
1017365
def parameters_signature(self):
        '''
            
        '''
        # Use x.type
        # x.name may be empty
        params = ",".join([str(x.type) for x in self._params])
        return '({})'.format(params)
1131875
def validate_signature(self):
        """"""
        if self.signature:
            return
        self.signature = self.file.read(8)
        if self.signature != png_signature:
            raise FormatError("PNG file has invalid signature.")
872624
async def verify_signature(self, msg: bytes, signature: bytes) -> bool:
        
        if not hasattr(Connection.verify_signature, "cb"):
            self.logger.debug("vcx_connection_verify_signature: Creating callback")
            Connection.verify_signature.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, c_bool))

        c_connection_handle = c_uint32(self.handle)
        c_msg_len = c_uint32(len(msg))
        c_signature_len = c_uint32(len(signature))

        result = await do_call('vcx_connection_verify_signature',
                               c_connection_handle,
                               msg,
                               c_msg_len,
                               signature,
                               c_signature_len,
                               Connection.verify_signature.cb)

        self.logger.debug("vcx_connection_verify_signature completed")
        return result
1131975
def getSignature(self, signatureKey, serialized):
        
        try:
            return Curve.calculateSignature(signatureKey, serialized)
        except InvalidKeyException as e:
            raise AssertionError(e)
531431
def request_signature(self, stringtosign):
        
        digest = hmac.new(
            self.secret_key.encode(ENCODING),
            stringtosign.encode(ENCODING),
            hashlib.sha1
        ).digest()
        return b64_string(digest)
358537
function getValidSignature (signature) {
    // require string
    if (typeof signature !== 'string') {
        throw new Error('signature must be string')
    }
    // split signature into moduleName and methodName
    var parts = signature.split('.')
    // require two parts
    if (parts.length !== 2) {
        throw new Error('invalid signature '+signature)
    }
    // module name is first part
    var moduleName = parts[0]
    // method name is second part
    var methodName = parts[1]
    // require names to be valid
    requireValidName(moduleName)
    requireValidName(methodName)
    // return module and function name
    return {
        signature: signature,
        methodName: methodName,
        moduleName: moduleName,
    }
}
333407
def sign(self, msg):
        '''
        
        '''
        if self.__signingkey is None:
            raise KeyTypeError('Wrong key type for operation')
        sig = ffi.new(C_SIGNATURE)
        lib.ed25519_SignMessage(
            sig, self.__signingkey, ffi.NULL, msg, len(msg))
        return ffi.get_bytes(sig)
1243928
private String makeSignature(ASTMethod method) {
        List<ASTType> paramTypes = new ArrayList<ASTType>();

        for (ASTParameter parameter : method.getParameters()) {
            paramTypes.add(parameter.getASTType());
        }

        return makeSignature(method.getName(), paramTypes);
    }
1203473
def _generate_signature(self, nonce, method, path, data):
        

        data_json = ""
        endpoint = path
        if method == "get":
            if data:
                query_string = self._get_params_for_sig(data)
                endpoint = "{}?{}".format(path, query_string)
        elif data:
            data_json = compact_json_dict(data)
        sig_str = ("{}{}{}{}".format(nonce, method.upper(), endpoint, data_json)).encode('utf-8')
        m = hmac.new(self.API_SECRET.encode('utf-8'), sig_str, hashlib.sha256)
        return base64.b64encode(m.digest())
1154648
def createSign(pParams, method, host_url, request_path, secret_key):
    
    sorted_params = sorted(pParams.items(), key=lambda d: d[0], reverse=False)
    encode_params = urllib.parse.urlencode(sorted_params)
    payload = [method, host_url, request_path, encode_params]
    payload = '\n'.join(payload)
    payload = payload.encode(encoding='UTF8')
    secret_key = secret_key.encode(encoding='UTF8')

    digest = hmac.new(secret_key, payload, digestmod=hashlib.sha256).digest()
    signature = base64.b64encode(digest)
    signature = signature.decode()
    return signature
513959
def signature(self):
        """"""
        if not use_signature:
            raise NotImplementedError("Python 3 only.")

        if self.static:
            parameters = \
                (Parameter(name='cls',
                           kind=Parameter.POSITIONAL_ONLY),)

        else:
            parameters = \
                (Parameter(name='self',
                           kind=Parameter.POSITIONAL_ONLY),)

        if self.input_transform:
            return signature(self.input_transform)

        if self.uses_request:
            fields = get_fields(self.request_type)
            if not self.static:
                if self.field_name not in fields:
                    raise NameError("field '{}' not found in {}".format(
                        self.field_name, self.request_name))
                fields.remove(self.field_name)
            parameters += tuple(
                Parameter(name=name, kind=Parameter.POSITIONAL_OR_KEYWORD,
                          default=None)
                for name in fields)

        return Signature(parameters)
868213
def fn_signature(callable, 
                 argument_transform=(lambda name: name),
                 default_transform=(lambda name, value: "%s=%s" % 
                                                        (name, repr(value))),
                 vararg_transform=(lambda name: "*" + name),
                 kwargs_transform=(lambda name: "**" + name)):
    """"""
    signature = []
    fn = get_fn(callable)
    avail_ac = fn_available_argcount(fn)
    kwargs = fn_kwargs(fn)
    argnames = fn_argnames(fn)
    for name in stop_at(argnames, avail_ac):
        if name in kwargs:
            signature.append(default_transform(name, kwargs[name]))
        else:
            signature.append(argument_transform(name))
    if fn_has_args(fn):
        if fn_has_kwargs(fn):
            signature.append(vararg_transform(argnames[-2]))
            signature.append(kwargs_transform(argnames[-1]))
        else:
            signature.append(vararg_transform(argnames[-1]))
    elif fn_has_kwargs(fn):
        signature.append(kwargs_transform(argnames[-1]))

    return signature
944129
def check_signature(signature, *args, **kwargs):
    
    return hmac.compare_digest(signature, create_signature(*args, **kwargs))
658263
def make_signature(signer_func, data_to_sign, public_algo,
                   hashed_subpackets, unhashed_subpackets, sig_type=0):
    """"""
    # pylint: disable=too-many-arguments
    header = struct.pack('>BBBB',
                         4,         # version
                         sig_type,  # rfc4880 (section-5.2.1)
                         public_algo,
                         8)         # hash_alg (SHA256)
    hashed = subpackets(*hashed_subpackets)
    unhashed = subpackets(*unhashed_subpackets)
    tail = b'\x04\xff' + struct.pack('>L', len(header) + len(hashed))
    data_to_hash = data_to_sign + header + hashed + tail

    log.debug('hashing %d bytes', len(data_to_hash))
    digest = hashlib.sha256(data_to_hash).digest()
    log.debug('signing digest: %s', util.hexlify(digest))
    params = signer_func(digest=digest)
    sig = b''.join(mpi(p) for p in params)

    return bytes(header + hashed + unhashed +
                 digest[:2] +  # used for decoder's sanity check
                 sig)
1312099
def get_key_signature(key='C'):
    
    if not is_valid_key(key):
        raise NoteFormatError("unrecognized format for key '%s'" % key)

    for couple in keys:
        if key in couple:
            accidentals = keys.index(couple) - 7
            return accidentals
362096
def generate_oauth_signature(self, params, url):
        
        if "oauth_signature" in params.keys():
            del params["oauth_signature"]

        base_request_uri = quote(url, "")
        params = self.sorted_params(params)
        params = self.normalize_parameters(params)
        query_params = ["{param_key}%3D{param_value}".format(param_key=key, param_value=value)
                        for key, value in params.items()]

        query_string = "%26".join(query_params)
        string_to_sign = "%s&%s&%s" % (self.method, base_request_uri, query_string)

        consumer_secret = str(self.consumer_secret)
        if self.version not in ["v1", "v2"]:
            consumer_secret += "&"

        hash_signature = HMAC(
            consumer_secret.encode(),
            str(string_to_sign).encode(),
            sha256
        ).digest()

        return b64encode(hash_signature).decode("utf-8").replace("\n", "")