1<?php
2
3/**
4 * Password Protected Trait for Private Keys
5 *
6 * PHP version 5
7 *
8 * @category  Crypt
9 * @package   Common
10 * @author    Jim Wigginton <terrafrost@php.net>
11 * @copyright 2015 Jim Wigginton
12 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
13 * @link      http://phpseclib.sourceforge.net
14 */
15
16namespace phpseclib3\Crypt\Common\Traits;
17
18/**
19 * Password Protected Trait for Private Keys
20 *
21 * @package Common
22 * @author  Jim Wigginton <terrafrost@php.net>
23 * @access  public
24 */
25trait PasswordProtected
26{
27    /**
28     * Password
29     *
30     * @var string|bool
31     */
32    private $password = false;
33
34    /**
35     * Sets the password
36     *
37     * Private keys can be encrypted with a password.  To unset the password, pass in the empty string or false.
38     * Or rather, pass in $password such that empty($password) && !is_string($password) is true.
39     *
40     * @see self::createKey()
41     * @see self::load()
42     * @access public
43     * @param string|bool $password
44     */
45    public function withPassword($password = false)
46    {
47        $new = clone $this;
48        $new->password = $password;
49        return $new;
50    }
51}
52