Skip to content

Commit

Permalink
Tweak formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sop committed May 15, 2019
1 parent e7da66e commit ecfa79f
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions lib/PKCS8/EncryptedPrivateKeyInfo.php
Expand Up @@ -15,7 +15,7 @@
use Sop\PKCS5\PBEScheme;

/**
* Implements PKCS #8 <i>EncryptedPrivateKeyInfo</i> ASN.1 type.
* Implements PKCS #8 *EncryptedPrivateKeyInfo* ASN.1 type.
*
* @see https://tools.ietf.org/html/rfc5208#section-6
*/
Expand All @@ -41,8 +41,7 @@ class EncryptedPrivateKeyInfo
* @param EncryptionAlgorithmIdentifier $algo
* @param string $data Ciphertext
*/
protected function __construct(EncryptionAlgorithmIdentifier $algo,
string $data)
protected function __construct(EncryptionAlgorithmIdentifier $algo, string $data)
{
$this->_algo = $algo;
$this->_data = $data;
Expand All @@ -64,9 +63,7 @@ public static function fromASN1(Sequence $seq): self
throw new \UnexpectedValueException(
sprintf('Algorithm %s not supported.', $algo->name()));
}
$data = $seq->at(1)
->asOctetString()
->string();
$data = $seq->at(1)->asOctetString()->string();
return new self($algo, $data);
}

Expand All @@ -93,7 +90,7 @@ public static function fromDER(string $data): self
*/
public static function fromPEM(PEM $pem): self
{
if (PEM::TYPE_ENCRYPTED_PRIVATE_KEY != $pem->type()) {
if (PEM::TYPE_ENCRYPTED_PRIVATE_KEY !== $pem->type()) {
throw new \UnexpectedValueException('Invalid PEM type.');
}
return self::fromDER($pem->data());
Expand Down Expand Up @@ -150,8 +147,7 @@ public function toPEM(): PEM
}

/**
* Decrypt PrivateKeyInfo from the encrypted data using password based
* encryption.
* Decrypt PrivateKeyInfo from the encrypted data using password based encryption.
*
* @param string $password Password
* @param null|Crypto $crypto Crypto engine, use default if not set
Expand All @@ -163,9 +159,8 @@ public function decryptWithPassword(string $password, ?Crypto $crypto = null): P
$ai = $this->_algo;
if (!($ai instanceof PBEAlgorithmIdentifier)) {
throw new \RuntimeException(
sprintf(
'Algorithm %s does not support' .
' password based encryption.', $ai->name()));
sprintf('Algorithm %s does not support' .
' password based encryption.', $ai->name()));
}
try {
$scheme = PBEScheme::fromAlgorithmIdentifier($ai, $crypto);
Expand All @@ -178,8 +173,7 @@ public function decryptWithPassword(string $password, ?Crypto $crypto = null): P
}

/**
* Initialize by encrypting a PrivateKeyInfo using password based
* encryption.
* Initialize by encrypting a PrivateKeyInfo using password based encryption.
*
* @param PrivateKeyInfo $pki Private key info
* @param PBEAlgorithmIdentifier $algo Encryption algorithm
Expand Down

0 comments on commit ecfa79f

Please sign in to comment.