Decorator for functions that require the private key to be defined.
188039
def requires_private_key(func):
    

    def func_wrapper(self, *args, **kwargs):
        if hasattr(self, "_DiffieHellman__private_key"):
            func(self, *args, **kwargs)
        else:
            self.generate_private_key()
            func(self, *args, **kwargs)

    return func_wrapper
1096590
def add(self, private_key):
        
        if not isinstance(private_key, PaillierPrivateKey):
            raise TypeError("private_key should be of type PaillierPrivateKey, "
                            "not %s" % type(private_key))
        self.__keyring[private_key.public_key] = private_key
111049
function makeModuleKeys(moduleIdentifier) {
  // Allocate a public/private key pair.
  function privateKey(fun) {
    const previous = hidden;

    hidden = privateKey;
    try {
      return fun();
    } finally {
      hidden = previous;
    }
  }
  function publicKey() {
    return hidden === privateKey;
  }
  publicKeys.add(publicKey);

  // Allow a private key to be used in lieu of the pair.
  defineProperty(
    privateKey, 'publicKey', { value: publicKey, enumerable: true });

  // We attach a module identifier to the public key to enable
  // whitelisting based on strings in a configuration without having
  // to load modules before storing their public key in a set.
  defineProperties(
    publicKey,
    {
      moduleIdentifier: { value: `${ moduleIdentifier }`, enumerable: true },
      call: { value: fCall, enumerable: true },
      apply: { value: fApply, enumerable: true },
    });

  /**
   * Wraps a value in a box so that only an approved
   * opener may unbox it.
   *
   * @param {*} value the value that will be given to
   *    an approved unboxer.
   * @param {!function(function():boolean):boolean} mayOpen
   *    receives the public key of the opener.
   *    Should return `true` to allow.
   *    This will be called in the context of the opener's
   *    private key, so the public key should also return true
   *    called with no arguments.
   * @return {!Box} a box that is opaque to any receivers that cannot
   *    unbox it.
   */
  function box(value, mayOpen) {
    if (typeof mayOpen !== 'function') {
      throw new TypeError(`Expected function not ${ mayOpen }`);
    }
    // Allocate an opaque token
    const newBox = new Box();
    boxes.set(
      newBox,
      freeze({ boxerPriv: privateKey, boxerPub: publicKey, value, mayOpen }));
    return newBox;
  }

  /**
   * Tries to open a box.
   *
   * @param {*} box the box to unbox.
   * @param {?function(function():boolean):boolean} ifFrom
   *    if the box may be opened by this unboxer's owner,
   *    then ifFrom receives the publicKey of the box creator.
   *    It should return true to allow unboxing to proceed.
   * @param {*} fallback a value to substitute if unboxing failed.
   *    Defaults to undefined.
   * @return {*} the value if unboxing is allowed or fallback otherwise.
   */
  function unbox(box, ifFrom, fallback) { // eslint-disable-line no-shadow
    if (ifFrom == null) { // eslint-disable-line
      ifFrom = () => true;
    }
    if (typeof ifFrom !== 'function') {
      throw new TypeError(`Expected function not ${ ifFrom }`);
    }
    const boxData = boxes.get(box);
    if (!boxData) {
      return fallback;
    }
    const { boxerPriv, boxerPub, value, mayOpen } = boxData;
    // Require mutual consent
    // TODO: Is this the object identity equivalent of an
    // out-of-order verify/decrypt fault?
    // http://world.std.com/~dtd/sign_encrypt/sign_encrypt7.html
    return (privateKey(() => mayOpen(publicKey)) === true &&
            boxerPriv(() => ifFrom(boxerPub)) === true) ?
      value :
      fallback;
  }

  const neverBoxed = {};
  /**
   * Like unbox but raises an exception if unboxing fails.
   * @param {*} box the box to unbox.
   * @param {?function(function():boolean):boolean} ifFrom
   *    if the box may be opened by this unboxer's owner,
   *    then ifFrom receives the publicKey of the box creator.
   *    It should return true to allow unboxing to proceed.
   * @return {*} the value if unboxing is allowed or fallback otherwise.
   */
  function unboxStrict(box, ifFrom) { // eslint-disable-line no-shadow
    const result = unbox(box, ifFrom, neverBoxed);
    if (result === neverBoxed) {
      throw new Error('Could not unbox');
    }
    return result;
  }

  return defineProperties(
    create(null),
    {
      // These close over private keys, so do not leak them.
      box: { value: box, enumerable: true },
      unbox: { value: unbox, enumerable: true },
      unboxStrict: { value: unboxStrict, enumerable: true },
      privateKey: { value: privateKey, enumerable: true },
      isPublicKey: { value: isPublicKey, enumerable: true },

      // Modules may allow access to this, perhaps via module object.
      // See cjs/index.js.
      publicKey: { value: publicKey, enumerable: true },
      [publicKeySymbol]: { value: publicKey, enumerable: true },
    });
}
635057
function(priv, network, _expectedAddress) {
    // Errors
    if (!priv || !network || !_expectedAddress) throw new Error('Missing argument !');
    if (!Helpers.isPrivateKeyValid(priv)) throw new Error('Private key is not valid !');
    //Processing
    let expectedAddress = _expectedAddress.toUpperCase().replace(/-/g, '');
    let kp = KeyPair.create(priv);
    let address = Address.toAddress(kp.publicKey.toString(), network);
    // Result
    return address === expectedAddress;
}
950502
def decorator(f):
    """"""
    @functools.wraps(f)
    def decoratored_function(*args, **kwargs):
        if args and len(args) == 1:
            return f(*args, **kwargs)

        if args:
            raise TypeError(
                "This decorator only accepts extra keyword arguments.")

        return lambda g: f(g, **kwargs)

    return decoratored_function
910688
def requires_auth(func):
    """"""
    @wraps(func)
    def auth_wrapper(self, *args, **kwargs):
        auth = False
        if hasattr(self, '_session'):
            auth = (self._session.auth or
                    self._session.headers.get('Authorization'))

        if auth:
            return func(self, *args, **kwargs)
        else:
            from .models import GitHubError
            # Mock a 401 response
            r = generate_fake_error_response(
                '{"message": "Requires authentication"}'
            )
            raise GitHubError(r)
    return auth_wrapper
469647
def auth_required(secret_key_func):
    
    def actual_decorator(obj):

        def test_func(request, *args, **kwargs):
            secret_key = secret_key_func(request, *args, **kwargs)
            return validate_signature(request, secret_key) or request.user.is_authenticated()

        decorator = request_passes_test(test_func)
        return wrap_object(obj, decorator)

    return actual_decorator
457656
def decorate(func, caller):
    
    evaldict = dict(_call_=caller, _func_=func)
    fun = FunctionMaker.create(
        func, "return _call_(_func_, %(shortsignature)s)",
        evaldict, __wrapped__=func)
    if hasattr(func, '__qualname__'):
        fun.__qualname__ = func.__qualname__
    return fun
954528
function decorator(fn) {
	return opt => (
		typeof opt==='function' ? fn(opt) : (target, key, desc) => {
			desc.value = fn(desc.value, opt, target, key, desc);
		}
	);
}
889478
def authenticated(function):
    """"""
    def wrapped(*args):
        """Wrap function."""
        try:
            return function(*args)
        except UPSError:
            _login(*args)
            return function(*args)
    return wrapped
650664
def str2cryptofunction(crypto_function_description):
    '''
       
    '''
    s = crypto_function_description.split('-')
    if len(s) != 3:
        raise ValueError('CryptoFunction description must be triplet separated by -')
    if s[0] != HOTP:
        raise ValueError('Unknown CryptoFunction kind %s' % s[0])
    algo = str2hashalgo(s[1])
    try:
        truncation_length = int(s[2])
        if truncation_length < 0 or truncation_length > 10:
            raise ValueError()
    except ValueError:
        raise ValueError('Invalid truncation length %s' % s[2])
    return CryptoFunction(algo, truncation_length)
40944
def __set_private_key(self, pk):
		
		self.__private_key = pk
		self.__public_key = pk.public_key()
969511
def login_required(func, permission=None):
    
    @wraps(func)
    def decorated_function(*args, **kwargs):
        if not check_token():
            return login()
        elif not nago.core.has_access(session.get('token')):
            return http403()
        return func(*args, **kwargs)
    return decorated_function
722213
def requires_lock(function):
    

    def new_lock_requiring_function(self, filename, *args, **kwargs):
        if self.owns_lock(filename):
            return function(self, filename, *args, **kwargs)
        else:
            raise RequiresLockException()

    return new_lock_requiring_function
1320659
def decorator(target):
    """"""

    def decorate(fn):
        spec = inspect.getargspec(fn)
        names = tuple(spec[0]) + spec[1:3] + (fn.__name__,)
        targ_name, fn_name = unique_symbols(names, 'target', 'fn')

        metadata = dict(target=targ_name, fn=fn_name)
        metadata.update(format_argspec_plus(spec, grouped=False))

        code = 'lambda %(args)s: %(target)s(%(fn)s, %(apply_kw)s)' % (
                metadata)
        decorated = eval(code, {targ_name: target, fn_name: fn})
        decorated.__defaults__ = getattr(fn, 'im_func', fn).__defaults__
        return update_wrapper(decorated, fn)
    return update_wrapper(decorate, target)
1271223
def create_key(kwargs=None, call=None):
    '''
    
    '''
    if call != 'function':
        log.error(
            'The create_key function must be called with -f or --function.'
        )
        return False

    try:
        result = query(
            method='account',
            command='keys',
            args={'name': kwargs['name'],
                  'public_key': kwargs['public_key']},
            http_method='post'
        )
    except KeyError:
        log.info('`name` and `public_key` arguments must be specified')
        return False

    return result
741723
def register(self, name):
        """"""
        def decorator(func):
            """Register decorated function."""
            self[name] = func
            return func

        return decorator