Conditions | 15 |
Paths | 15 |
Total Lines | 43 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
107 | public static function fromUnencryptedElement( |
||
108 | AbstractXMLElement $element, |
||
109 | XMLSecurityKey $key |
||
110 | ): EncryptedElementInterface { |
||
111 | $xml = $element->toXML(); |
||
112 | |||
113 | $enc = new XMLSecEnc(); |
||
114 | $enc->setNode($xml); |
||
115 | $enc->type = XMLSecEnc::Element; |
||
116 | |||
117 | switch ($key->type) { |
||
118 | case XMLSecurityKey::TRIPLEDES_CBC: |
||
119 | case XMLSecurityKey::AES128_CBC: |
||
120 | case XMLSecurityKey::AES192_CBC: |
||
121 | case XMLSecurityKey::AES256_CBC: |
||
122 | case XMLSecurityKey::AES128_GCM: |
||
123 | case XMLSecurityKey::AES192_GCM: |
||
124 | case XMLSecurityKey::AES256_GCM: |
||
125 | $symmetricKey = $key; |
||
126 | break; |
||
127 | |||
128 | case XMLSecurityKey::RSA_1_5: |
||
129 | case XMLSecurityKey::RSA_SHA1: |
||
130 | case XMLSecurityKey::RSA_SHA256: |
||
131 | case XMLSecurityKey::RSA_SHA384: |
||
132 | case XMLSecurityKey::RSA_SHA512: |
||
133 | case XMLSecurityKey::RSA_OAEP: |
||
134 | case XMLSecurityKey::RSA_OAEP_MGF1P: |
||
135 | $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC); |
||
136 | $symmetricKey->generateSessionKey(); |
||
137 | |||
138 | $enc->encryptKey($key, $symmetricKey); |
||
139 | |||
140 | break; |
||
141 | |||
142 | default: |
||
143 | throw new \Exception('Unknown key type for encryption: ' . $key->type); |
||
144 | } |
||
145 | |||
146 | $dom = $enc->encryptNode($symmetricKey); |
||
147 | /** @var \SimpleSAML\XMLSecurity\XML\xenc\EncryptedData $encData */ |
||
148 | $encData = EncryptedData::fromXML($dom); |
||
149 | return new static($encData, []); |
||
|
|||
150 | } |
||
196 |