AuthenticationVerificationResult::error()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Copyright 2015 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupRa\RaBundle\Service\U2f;
20
21
final class AuthenticationVerificationResult
22
{
23
    const STATUS_SUCCESS = 'SUCCESS';
24
25
    /**
26
     * The API behaved in an unexpected manner.
27
     */
28
    const STATUS_API_ERROR = 'API_ERROR';
29
30
    /**
31
     * No registration with the given key handle is known.
32
     */
33
    const STATUS_UNKNOWN_KEY_HANDLE = 'UNKNOWN_KEY_HANDLE';
34
35
    /**
36
     * Device responded with an error.
37
     */
38
    const STATUS_DEVICE_ERROR = 'DEVICE_ERROR';
39
40
    /**
41
     * The response challenge did not match the request challenge.
42
     */
43
    const STATUS_REQUEST_RESPONSE_MISMATCH = 'REQUEST_RESPONSE_MISMATCH';
44
45
    /**
46
     * The response was signed by another party than the device, indicating it was tampered with.
47
     */
48
    const STATUS_RESPONSE_NOT_SIGNED_BY_DEVICE = 'RESPONSE_NOT_SIGNED_BY_DEVICE';
49
50
    /**
51
     * The decoding of the device's public key failed.
52
     */
53
    const STATUS_PUBLIC_KEY_DECODING_FAILED = 'PUBLIC_KEY_DECODING_FAILED';
54
55
    /**
56
     * A message's AppID didn't match the server's
57
     */
58
    const STATUS_APP_ID_MISMATCH = 'APP_ID_MISMATCH';
59
60
    /**
61
     * @var string
62
     */
63
    private $status;
64
65
    public static function success()
66
    {
67
        return new self(self::STATUS_SUCCESS);
68
    }
69
70
    /**
71
     * @param string $status
72
     * @return AuthenticationVerificationResult
73
     */
74
    public static function error($status)
75
    {
76
        return new self($status);
77
    }
78
79
    public static function apiError()
80
    {
81
        return new self(self::STATUS_API_ERROR);
82
    }
83
84
    private function __construct($status)
85
    {
86
        $this->status = $status;
87
    }
88
89
    /**
90
     * @return bool
91
     */
92
    public function wasSuccessful()
93
    {
94
        return $this->status === self::STATUS_SUCCESS;
95
    }
96
97
    /**
98
     * @return bool
99
     */
100
    public function didDeviceReportAnyError()
101
    {
102
        return $this->status === self::STATUS_DEVICE_ERROR;
103
    }
104
}
105