Conditions | 1 |
Paths | 1 |
Total Lines | 26 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | protected function formatJson($response) |
||
15 | { |
||
16 | parent::formatJson($response); |
||
|
|||
17 | $response->getHeaders()->set('Content-Type', 'application/json+25519; charset=UTF-8'); |
||
18 | |||
19 | // Retrieve the token object from the user |
||
20 | $token = Yii::$app->user->getIdentity()->getToken(); |
||
21 | |||
22 | // Calculate the keypair |
||
23 | $keyPair = \Sodium\crypto_box_keypair_from_secretkey_and_publickey( |
||
24 | \base64_decode($token->getCryptToken()->secret_box_kp), |
||
25 | \base64_decode($token->client_public) |
||
26 | ); |
||
27 | |||
28 | // Calculate a nonce and set it in the header |
||
29 | $nonce = \Sodium\randombytes_buf(\Sodium\CRYPTO_BOX_NONCEBYTES); |
||
30 | $response->getHeaders()->set('x-nonce', \base64_encode($nonce)); |
||
31 | $response->getHeaders()->set('x-pubkey', \base64_encode($token->getCryptToken()->getBoxPublicKey())); |
||
32 | |||
33 | // Encrypt the content |
||
34 | $response->content = \base64_encode(\Sodium\crypto_box( |
||
35 | $response->content, |
||
36 | $nonce, |
||
37 | $keyPair |
||
38 | )); |
||
39 | } |
||
40 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: