Completed
Push — master ( 580028...d7e9e8 )
by Charles
02:19
created

OneTimeKeyAction   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 17 1
1
<?php
2
3
namespace yrc\api\actions;
4
5
use yrc\rest\Action as RestAction;
6
use yrc\api\models\TokenKeyPair;
7
use Sodium;
8
use Yii;
9
10
class OneTimeKeyAction extends RestAction
11
{
12
    /**
13
     * Generates a one time key pair to authenticate further authentication sessions
14
     * @return array
15
     */
16
    public function get($params)
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
    {
18
        // Generate a one time key pair
19
        $model = TokenKeyPair::generate(TokenKeyPair::OTK_TYPE);
20
21
        // Return the public keys, and a signature of the public key
22
        return [
23
            'public'        => \base64_encode($model->getBoxPublicKey()),
24
            'signing'       => \base64_encode($model->getSignPublicKey()),
25
            'signature'     => \base64_encode(\Sodium\crypto_sign(
26
                $model->getBoxPublicKey(),
27
                \base64_decode($model->secret_sign_kp)
28
            )),
29
            'hash'          => $model->hash,
30
            'expires_at'    => $model->expires_at
31
        ];
32
    }
33
}