@@ -64,7 +64,9 @@ |
||
64 | 64 | * @return null|CompressionAlgorithm |
65 | 65 | */ |
66 | 66 | public function get($alg){ |
67 | - if(!$this->isSupported($alg)) return null; |
|
67 | + if(!$this->isSupported($alg)) { |
|
68 | + return null; |
|
69 | + } |
|
68 | 70 | return $this->algorithms[$alg]; |
69 | 71 | } |
70 | 72 | } |
71 | 73 | \ No newline at end of file |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | private $algorithms = []; |
29 | 29 | |
30 | - private function __construct(){ |
|
30 | + private function __construct() { |
|
31 | 31 | |
32 | 32 | $this->algorithms[CompressionAlgorithmsNames::Deflate] = new Deflate; |
33 | 33 | $this->algorithms[CompressionAlgorithmsNames::GZip] = new GZip; |
@@ -35,13 +35,13 @@ discard block |
||
35 | 35 | |
36 | 36 | } |
37 | 37 | |
38 | - private function __clone(){} |
|
38 | + private function __clone() {} |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * @return CompressionAlgorithms_Registry |
42 | 42 | */ |
43 | - public static function getInstance(){ |
|
44 | - if(!is_object(self::$instance)){ |
|
43 | + public static function getInstance() { |
|
44 | + if (!is_object(self::$instance)) { |
|
45 | 45 | self::$instance = new CompressionAlgorithms_Registry(); |
46 | 46 | } |
47 | 47 | return self::$instance; |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @param string $alg |
52 | 52 | * @return bool |
53 | 53 | */ |
54 | - public function isSupported($alg){ |
|
54 | + public function isSupported($alg) { |
|
55 | 55 | return array_key_exists($alg, $this->algorithms); |
56 | 56 | } |
57 | 57 | |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | * @param $alg |
60 | 60 | * @return null|CompressionAlgorithm |
61 | 61 | */ |
62 | - public function get($alg){ |
|
63 | - if(!$this->isSupported($alg)) return null; |
|
62 | + public function get($alg) { |
|
63 | + if (!$this->isSupported($alg)) return null; |
|
64 | 64 | return $this->algorithms[$alg]; |
65 | 65 | } |
66 | 66 | } |
67 | 67 | \ No newline at end of file |
@@ -27,7 +27,7 @@ |
||
27 | 27 | /** |
28 | 28 | * @param string $secret |
29 | 29 | */ |
30 | - public function __construct($secret){ |
|
30 | + public function __construct($secret) { |
|
31 | 31 | $this->secret = $secret; |
32 | 32 | } |
33 | 33 |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * @param string $pem |
25 | 25 | * @return X509Certificate |
26 | 26 | */ |
27 | - static public function buildFromPEM($pem){ |
|
27 | + static public function buildFromPEM($pem) { |
|
28 | 28 | return new _X509Certificate($pem); |
29 | 29 | } |
30 | 30 | } |
31 | 31 | \ No newline at end of file |
@@ -22,7 +22,7 @@ |
||
22 | 22 | * Interface IJWK |
23 | 23 | * @package jwk |
24 | 24 | */ |
25 | -interface IJWK extends IReadOnlyJWK { |
|
25 | +interface IJWK extends IReadOnlyJWK { |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * @param string $kid |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | const Exponent = 'e'; |
37 | 37 | |
38 | - public static $public_key_params = array ( self::Modulus, self::Exponent); |
|
38 | + public static $public_key_params = array(self::Modulus, self::Exponent); |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * The "d" (private exponent) parameter contains the private exponent |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | |
81 | 81 | |
82 | - public static $producers_private_key_params = array ( |
|
82 | + public static $producers_private_key_params = array( |
|
83 | 83 | self::FirstPrimeFactor, |
84 | 84 | self::SecondPrimeFactor, |
85 | 85 | self::FirstFactorCRTExponent, |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | protected function __construct(Key $secret, $headers = array()) |
41 | 41 | { |
42 | 42 | |
43 | - if(empty($secret)) |
|
43 | + if (empty($secret)) |
|
44 | 44 | throw new InvalidOctetSequenceJWKException('secret is not set!.'); |
45 | 45 | |
46 | 46 | $this->set[JSONWebKeyParameters::KeyType] = new StringOrURI(JSONWebKeyTypes::OctetSequence); |
47 | 47 | |
48 | 48 | parent::__construct($headers); |
49 | 49 | |
50 | - if(count($headers) === 0 ) return; |
|
50 | + if (count($headers) === 0) return; |
|
51 | 51 | |
52 | 52 | $b64 = new Base64UrlRepresentation(); |
53 | 53 | |
@@ -72,17 +72,17 @@ discard block |
||
72 | 72 | * @param string $use |
73 | 73 | * @return IJWK |
74 | 74 | */ |
75 | - static public function fromSecret(Key $key, $alg = null, $use = JSONWebKeyPublicKeyUseValues::Signature){ |
|
75 | + static public function fromSecret(Key $key, $alg = null, $use = JSONWebKeyPublicKeyUseValues::Signature) { |
|
76 | 76 | |
77 | 77 | $headers = array(); |
78 | 78 | |
79 | - if(!empty($alg)) { |
|
79 | + if (!empty($alg)) { |
|
80 | 80 | |
81 | 81 | $headers[JSONWebKeyParameters::Algorithm] = $alg; |
82 | 82 | } |
83 | 83 | |
84 | 84 | $headers[JSONWebKeyParameters::PublicKeyUse] = $use; |
85 | 85 | |
86 | - return new OctetSequenceJWK($key, $headers) ; |
|
86 | + return new OctetSequenceJWK($key, $headers); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | \ No newline at end of file |
@@ -40,14 +40,17 @@ |
||
40 | 40 | protected function __construct(Key $secret, $headers = array()) |
41 | 41 | { |
42 | 42 | |
43 | - if(empty($secret)) |
|
44 | - throw new InvalidOctetSequenceJWKException('secret is not set!.'); |
|
43 | + if(empty($secret)) { |
|
44 | + throw new InvalidOctetSequenceJWKException('secret is not set!.'); |
|
45 | + } |
|
45 | 46 | |
46 | 47 | $this->set[JSONWebKeyParameters::KeyType] = new StringOrURI(JSONWebKeyTypes::OctetSequence); |
47 | 48 | |
48 | 49 | parent::__construct($headers); |
49 | 50 | |
50 | - if(count($headers) === 0 ) return; |
|
51 | + if(count($headers) === 0 ) { |
|
52 | + return; |
|
53 | + } |
|
51 | 54 | |
52 | 55 | $b64 = new Base64UrlRepresentation(); |
53 | 56 |
@@ -46,8 +46,7 @@ discard block |
||
46 | 46 | * @param string $use |
47 | 47 | * @param null|string $kid |
48 | 48 | */ |
49 | - public function __construct |
|
50 | - ( |
|
49 | + public function __construct( |
|
51 | 50 | $alg = JSONWebSignatureAndEncryptionAlgorithms::RS256, |
52 | 51 | $use = JSONWebKeyPublicKeyUseValues::Signature, |
53 | 52 | $kid = null |
@@ -58,7 +57,7 @@ discard block |
||
58 | 57 | $this->kid = $kid; |
59 | 58 | } |
60 | 59 | |
61 | - public function getAlg(){ |
|
60 | + public function getAlg() { |
|
62 | 61 | return $this->alg; |
63 | 62 | } |
64 | 63 |
@@ -36,15 +36,14 @@ |
||
36 | 36 | * @param string $alg |
37 | 37 | * @param string $use |
38 | 38 | */ |
39 | - public function __construct |
|
40 | - ( |
|
39 | + public function __construct( |
|
41 | 40 | $key_pem, |
42 | 41 | $password = self::WithoutPassword, |
43 | 42 | $alg = JSONWebSignatureAndEncryptionAlgorithms::RS256, |
44 | 43 | $use = JSONWebKeyPublicKeyUseValues::Signature |
45 | 44 | ) |
46 | 45 | { |
47 | - parent::__construct($key_pem , $alg, $use); |
|
46 | + parent::__construct($key_pem, $alg, $use); |
|
48 | 47 | $this->password = $password; |
49 | 48 | } |
50 | 49 | /** |
@@ -41,28 +41,24 @@ discard block |
||
41 | 41 | static public function build(IJWKSpecification $spec) |
42 | 42 | { |
43 | 43 | |
44 | - if(is_null($spec)) throw new \InvalidArgumentException('missing spec param'); |
|
44 | + if (is_null($spec)) throw new \InvalidArgumentException('missing spec param'); |
|
45 | 45 | |
46 | - $algorithm = DigitalSignatures_MACs_Registry::getInstance()->get |
|
47 | - ( |
|
46 | + $algorithm = DigitalSignatures_MACs_Registry::getInstance()->get( |
|
48 | 47 | $spec->getAlg() |
49 | 48 | ); |
50 | 49 | |
51 | - if(is_null($algorithm)) |
|
52 | - $algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get |
|
53 | - ( |
|
50 | + if (is_null($algorithm)) |
|
51 | + $algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get( |
|
54 | 52 | $spec->getAlg() |
55 | 53 | ); |
56 | 54 | |
57 | - if(is_null($algorithm)) |
|
58 | - $algorithm = KeyManagementAlgorithms_Registry::getInstance()->get |
|
59 | - ( |
|
55 | + if (is_null($algorithm)) |
|
56 | + $algorithm = KeyManagementAlgorithms_Registry::getInstance()->get( |
|
60 | 57 | $spec->getAlg() |
61 | 58 | ); |
62 | 59 | |
63 | - if(is_null($algorithm)) |
|
64 | - throw new InvalidJWKAlgorithm |
|
65 | - ( |
|
60 | + if (is_null($algorithm)) |
|
61 | + throw new InvalidJWKAlgorithm( |
|
66 | 62 | sprintf( |
67 | 63 | 'alg %s not supported!', |
68 | 64 | $spec->getAlg() |
@@ -70,31 +66,27 @@ discard block |
||
70 | 66 | ); |
71 | 67 | |
72 | 68 | |
73 | - if($algorithm->getKeyType() !== JSONWebKeyTypes::OctetSequence) |
|
74 | - throw new InvalidJWKAlgorithm |
|
75 | - ( |
|
76 | - sprintf |
|
77 | - ( |
|
69 | + if ($algorithm->getKeyType() !== JSONWebKeyTypes::OctetSequence) |
|
70 | + throw new InvalidJWKAlgorithm( |
|
71 | + sprintf( |
|
78 | 72 | 'key type %s not supported!', |
79 | 73 | $algorithm->getKeyType() |
80 | 74 | ) |
81 | 75 | ); |
82 | 76 | |
83 | - if(!($spec instanceof OctetSequenceJWKSpecification)) throw new JWKInvalidSpecException; |
|
77 | + if (!($spec instanceof OctetSequenceJWKSpecification)) throw new JWKInvalidSpecException; |
|
84 | 78 | |
85 | 79 | $shared_secret = $spec->getSharedSecret(); |
86 | 80 | $secret_len = strlen($shared_secret); |
87 | 81 | |
88 | - if($secret_len === 0 ) |
|
82 | + if ($secret_len === 0) |
|
89 | 83 | { |
90 | 84 | $generator = Utils_Registry::getInstance()->get(Utils_Registry::RandomNumberGeneratorService); |
91 | 85 | $shared_secret = $generator->invoke($algorithm->getMinKeyLen() / 8); |
92 | 86 | } |
93 | 87 | |
94 | - return OctetSequenceJWK::fromSecret |
|
95 | - ( |
|
96 | - new SymmetricSharedKey |
|
97 | - ( |
|
88 | + return OctetSequenceJWK::fromSecret( |
|
89 | + new SymmetricSharedKey( |
|
98 | 90 | $shared_secret |
99 | 91 | ), |
100 | 92 | $spec->getAlg(), |
@@ -41,37 +41,42 @@ discard block |
||
41 | 41 | static public function build(IJWKSpecification $spec) |
42 | 42 | { |
43 | 43 | |
44 | - if(is_null($spec)) throw new \InvalidArgumentException('missing spec param'); |
|
44 | + if(is_null($spec)) { |
|
45 | + throw new \InvalidArgumentException('missing spec param'); |
|
46 | + } |
|
45 | 47 | |
46 | 48 | $algorithm = DigitalSignatures_MACs_Registry::getInstance()->get |
47 | 49 | ( |
48 | 50 | $spec->getAlg() |
49 | 51 | ); |
50 | 52 | |
51 | - if(is_null($algorithm)) |
|
52 | - $algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get |
|
53 | + if(is_null($algorithm)) { |
|
54 | + $algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get |
|
53 | 55 | ( |
54 | 56 | $spec->getAlg() |
55 | 57 | ); |
58 | + } |
|
56 | 59 | |
57 | - if(is_null($algorithm)) |
|
58 | - $algorithm = KeyManagementAlgorithms_Registry::getInstance()->get |
|
60 | + if(is_null($algorithm)) { |
|
61 | + $algorithm = KeyManagementAlgorithms_Registry::getInstance()->get |
|
59 | 62 | ( |
60 | 63 | $spec->getAlg() |
61 | 64 | ); |
65 | + } |
|
62 | 66 | |
63 | - if(is_null($algorithm)) |
|
64 | - throw new InvalidJWKAlgorithm |
|
67 | + if(is_null($algorithm)) { |
|
68 | + throw new InvalidJWKAlgorithm |
|
65 | 69 | ( |
66 | 70 | sprintf( |
67 | 71 | 'alg %s not supported!', |
68 | 72 | $spec->getAlg() |
69 | 73 | ) |
70 | 74 | ); |
75 | + } |
|
71 | 76 | |
72 | 77 | |
73 | - if($algorithm->getKeyType() !== JSONWebKeyTypes::OctetSequence) |
|
74 | - throw new InvalidJWKAlgorithm |
|
78 | + if($algorithm->getKeyType() !== JSONWebKeyTypes::OctetSequence) { |
|
79 | + throw new InvalidJWKAlgorithm |
|
75 | 80 | ( |
76 | 81 | sprintf |
77 | 82 | ( |
@@ -79,8 +84,11 @@ discard block |
||
79 | 84 | $algorithm->getKeyType() |
80 | 85 | ) |
81 | 86 | ); |
87 | + } |
|
82 | 88 | |
83 | - if(!($spec instanceof OctetSequenceJWKSpecification)) throw new JWKInvalidSpecException; |
|
89 | + if(!($spec instanceof OctetSequenceJWKSpecification)) { |
|
90 | + throw new JWKInvalidSpecException; |
|
91 | + } |
|
84 | 92 | |
85 | 93 | $shared_secret = $spec->getSharedSecret(); |
86 | 94 | $secret_len = strlen($shared_secret); |