GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Failed
Push — master ( 405cf3...79c9ba )
by Joni
04:48
created
lib/X509/GeneralName/IPv6Address.php 3 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X509\GeneralName;
6 6
 
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
     protected static function _wordsToIPv6String(array $words): string
44 44
     {
45 45
         $groups = array_map(
46
-            function ($word) {
46
+            function($word) {
47 47
                 return sprintf('%04x', $word);
48 48
             }, $words);
49 49
         return implode(':', $groups);
Please login to merge, or discard this patch.
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -6,59 +6,59 @@
 block discarded – undo
6 6
 
7 7
 class IPv6Address extends IPAddress
8 8
 {
9
-    /**
10
-     * Initialize from octets.
11
-     *
12
-     * @param string $octets
13
-     *
14
-     * @throws \InvalidArgumentException
15
-     *
16
-     * @return self
17
-     */
18
-    public static function fromOctets(string $octets): self
19
-    {
20
-        $mask = null;
21
-        $words = unpack('n*', $octets) ?: [];
22
-        switch (count($words)) {
23
-            case 8:
24
-                $ip = self::_wordsToIPv6String($words);
25
-                break;
26
-            case 16:
27
-                $ip = self::_wordsToIPv6String(array_slice($words, 0, 8));
28
-                $mask = self::_wordsToIPv6String(array_slice($words, 8, 8));
29
-                break;
30
-            default:
31
-                throw new \UnexpectedValueException('Invalid IPv6 octet length.');
32
-        }
33
-        return new self($ip, $mask);
34
-    }
9
+	/**
10
+	 * Initialize from octets.
11
+	 *
12
+	 * @param string $octets
13
+	 *
14
+	 * @throws \InvalidArgumentException
15
+	 *
16
+	 * @return self
17
+	 */
18
+	public static function fromOctets(string $octets): self
19
+	{
20
+		$mask = null;
21
+		$words = unpack('n*', $octets) ?: [];
22
+		switch (count($words)) {
23
+			case 8:
24
+				$ip = self::_wordsToIPv6String($words);
25
+				break;
26
+			case 16:
27
+				$ip = self::_wordsToIPv6String(array_slice($words, 0, 8));
28
+				$mask = self::_wordsToIPv6String(array_slice($words, 8, 8));
29
+				break;
30
+			default:
31
+				throw new \UnexpectedValueException('Invalid IPv6 octet length.');
32
+		}
33
+		return new self($ip, $mask);
34
+	}
35 35
 
36
-    /**
37
-     * Convert an array of 16 bit words to an IPv6 string representation.
38
-     *
39
-     * @param int[] $words
40
-     *
41
-     * @return string
42
-     */
43
-    protected static function _wordsToIPv6String(array $words): string
44
-    {
45
-        $groups = array_map(
46
-            function ($word) {
47
-                return sprintf('%04x', $word);
48
-            }, $words);
49
-        return implode(':', $groups);
50
-    }
36
+	/**
37
+	 * Convert an array of 16 bit words to an IPv6 string representation.
38
+	 *
39
+	 * @param int[] $words
40
+	 *
41
+	 * @return string
42
+	 */
43
+	protected static function _wordsToIPv6String(array $words): string
44
+	{
45
+		$groups = array_map(
46
+			function ($word) {
47
+				return sprintf('%04x', $word);
48
+			}, $words);
49
+		return implode(':', $groups);
50
+	}
51 51
 
52
-    /**
53
-     * {@inheritdoc}
54
-     */
55
-    protected function _octets(): string
56
-    {
57
-        $words = array_map('hexdec', explode(':', $this->_ip));
58
-        if (isset($this->_mask)) {
59
-            $words = array_merge($words,
60
-                array_map('hexdec', explode(':', $this->_mask)));
61
-        }
62
-        return pack('n*', ...$words);
63
-    }
52
+	/**
53
+	 * {@inheritdoc}
54
+	 */
55
+	protected function _octets(): string
56
+	{
57
+		$words = array_map('hexdec', explode(':', $this->_ip));
58
+		if (isset($this->_mask)) {
59
+			$words = array_merge($words,
60
+				array_map('hexdec', explode(':', $this->_mask)));
61
+		}
62
+		return pack('n*', ...$words);
63
+	}
64 64
 }
Please login to merge, or discard this patch.
Switch Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -20,15 +20,15 @@
 block discarded – undo
20 20
         $mask = null;
21 21
         $words = unpack('n*', $octets) ?: [];
22 22
         switch (count($words)) {
23
-            case 8:
24
-                $ip = self::_wordsToIPv6String($words);
25
-                break;
26
-            case 16:
27
-                $ip = self::_wordsToIPv6String(array_slice($words, 0, 8));
28
-                $mask = self::_wordsToIPv6String(array_slice($words, 8, 8));
29
-                break;
30
-            default:
31
-                throw new \UnexpectedValueException('Invalid IPv6 octet length.');
23
+        case 8:
24
+            $ip = self::_wordsToIPv6String($words);
25
+            break;
26
+        case 16:
27
+            $ip = self::_wordsToIPv6String(array_slice($words, 0, 8));
28
+            $mask = self::_wordsToIPv6String(array_slice($words, 8, 8));
29
+            break;
30
+        default:
31
+            throw new \UnexpectedValueException('Invalid IPv6 octet length.');
32 32
         }
33 33
         return new self($ip, $mask);
34 34
     }
Please login to merge, or discard this patch.
lib/X509/GeneralName/IPAddress.php 3 patches
Switch Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -55,15 +55,15 @@
 block discarded – undo
55 55
     {
56 56
         $octets = $el->asOctetString()->string();
57 57
         switch (strlen($octets)) {
58
-            case 4:
59
-            case 8:
60
-                return IPv4Address::fromOctets($octets);
61
-            case 16:
62
-            case 32:
63
-                return IPv6Address::fromOctets($octets);
64
-            default:
65
-                throw new \UnexpectedValueException(
66
-                    'Invalid octet length for IP address.');
58
+        case 4:
59
+        case 8:
60
+            return IPv4Address::fromOctets($octets);
61
+        case 16:
62
+        case 32:
63
+            return IPv6Address::fromOctets($octets);
64
+        default:
65
+            throw new \UnexpectedValueException(
66
+                'Invalid octet length for IP address.');
67 67
         }
68 68
     }
69 69
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X509\GeneralName;
6 6
 
Please login to merge, or discard this patch.
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -19,110 +19,110 @@
 block discarded – undo
19 19
  */
20 20
 abstract class IPAddress extends GeneralName
21 21
 {
22
-    /**
23
-     * IP address.
24
-     *
25
-     * @var string
26
-     */
27
-    protected $_ip;
22
+	/**
23
+	 * IP address.
24
+	 *
25
+	 * @var string
26
+	 */
27
+	protected $_ip;
28 28
 
29
-    /**
30
-     * Subnet mask.
31
-     *
32
-     * @var null|string
33
-     */
34
-    protected $_mask;
29
+	/**
30
+	 * Subnet mask.
31
+	 *
32
+	 * @var null|string
33
+	 */
34
+	protected $_mask;
35 35
 
36
-    /**
37
-     * Constructor.
38
-     *
39
-     * @param string      $ip
40
-     * @param null|string $mask
41
-     */
42
-    public function __construct(string $ip, ?string $mask = null)
43
-    {
44
-        $this->_tag = self::TAG_IP_ADDRESS;
45
-        $this->_ip = $ip;
46
-        $this->_mask = $mask;
47
-    }
36
+	/**
37
+	 * Constructor.
38
+	 *
39
+	 * @param string      $ip
40
+	 * @param null|string $mask
41
+	 */
42
+	public function __construct(string $ip, ?string $mask = null)
43
+	{
44
+		$this->_tag = self::TAG_IP_ADDRESS;
45
+		$this->_ip = $ip;
46
+		$this->_mask = $mask;
47
+	}
48 48
 
49
-    /**
50
-     * {@inheritdoc}
51
-     *
52
-     * @return self
53
-     */
54
-    public static function fromChosenASN1(UnspecifiedType $el): GeneralName
55
-    {
56
-        $octets = $el->asOctetString()->string();
57
-        switch (strlen($octets)) {
58
-            case 4:
59
-            case 8:
60
-                return IPv4Address::fromOctets($octets);
61
-            case 16:
62
-            case 32:
63
-                return IPv6Address::fromOctets($octets);
64
-            default:
65
-                throw new \UnexpectedValueException(
66
-                    'Invalid octet length for IP address.');
67
-        }
68
-    }
49
+	/**
50
+	 * {@inheritdoc}
51
+	 *
52
+	 * @return self
53
+	 */
54
+	public static function fromChosenASN1(UnspecifiedType $el): GeneralName
55
+	{
56
+		$octets = $el->asOctetString()->string();
57
+		switch (strlen($octets)) {
58
+			case 4:
59
+			case 8:
60
+				return IPv4Address::fromOctets($octets);
61
+			case 16:
62
+			case 32:
63
+				return IPv6Address::fromOctets($octets);
64
+			default:
65
+				throw new \UnexpectedValueException(
66
+					'Invalid octet length for IP address.');
67
+		}
68
+	}
69 69
 
70
-    /**
71
-     * {@inheritdoc}
72
-     */
73
-    public function string(): string
74
-    {
75
-        return $this->_ip . (isset($this->_mask) ? '/' . $this->_mask : '');
76
-    }
70
+	/**
71
+	 * {@inheritdoc}
72
+	 */
73
+	public function string(): string
74
+	{
75
+		return $this->_ip . (isset($this->_mask) ? '/' . $this->_mask : '');
76
+	}
77 77
 
78
-    /**
79
-     * Get IP address as a string.
80
-     *
81
-     * @return string
82
-     */
83
-    public function address(): string
84
-    {
85
-        return $this->_ip;
86
-    }
78
+	/**
79
+	 * Get IP address as a string.
80
+	 *
81
+	 * @return string
82
+	 */
83
+	public function address(): string
84
+	{
85
+		return $this->_ip;
86
+	}
87 87
 
88
-    /**
89
-     * Check whether mask is present.
90
-     *
91
-     * @return bool
92
-     */
93
-    public function hasMask(): bool
94
-    {
95
-        return isset($this->_mask);
96
-    }
88
+	/**
89
+	 * Check whether mask is present.
90
+	 *
91
+	 * @return bool
92
+	 */
93
+	public function hasMask(): bool
94
+	{
95
+		return isset($this->_mask);
96
+	}
97 97
 
98
-    /**
99
-     * Get subnet mask as a string.
100
-     *
101
-     * @throws \LogicException If not set
102
-     *
103
-     * @return string
104
-     */
105
-    public function mask(): string
106
-    {
107
-        if (!$this->hasMask()) {
108
-            throw new \LogicException('mask is not set.');
109
-        }
110
-        return $this->_mask;
111
-    }
98
+	/**
99
+	 * Get subnet mask as a string.
100
+	 *
101
+	 * @throws \LogicException If not set
102
+	 *
103
+	 * @return string
104
+	 */
105
+	public function mask(): string
106
+	{
107
+		if (!$this->hasMask()) {
108
+			throw new \LogicException('mask is not set.');
109
+		}
110
+		return $this->_mask;
111
+	}
112 112
 
113
-    /**
114
-     * Get octet representation of the IP address.
115
-     *
116
-     * @return string
117
-     */
118
-    abstract protected function _octets(): string;
113
+	/**
114
+	 * Get octet representation of the IP address.
115
+	 *
116
+	 * @return string
117
+	 */
118
+	abstract protected function _octets(): string;
119 119
 
120
-    /**
121
-     * {@inheritdoc}
122
-     */
123
-    protected function _choiceASN1(): TaggedType
124
-    {
125
-        return new ImplicitlyTaggedType($this->_tag,
126
-            new OctetString($this->_octets()));
127
-    }
120
+	/**
121
+	 * {@inheritdoc}
122
+	 */
123
+	protected function _choiceASN1(): TaggedType
124
+	{
125
+		return new ImplicitlyTaggedType($this->_tag,
126
+			new OctetString($this->_octets()));
127
+	}
128 128
 }
Please login to merge, or discard this patch.
lib/X509/GeneralName/RegisteredID.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -16,58 +16,58 @@
 block discarded – undo
16 16
  */
17 17
 class RegisteredID extends GeneralName
18 18
 {
19
-    /**
20
-     * Object identifier.
21
-     *
22
-     * @var string
23
-     */
24
-    protected $_oid;
19
+	/**
20
+	 * Object identifier.
21
+	 *
22
+	 * @var string
23
+	 */
24
+	protected $_oid;
25 25
 
26
-    /**
27
-     * Constructor.
28
-     *
29
-     * @param string $oid OID in dotted format
30
-     */
31
-    public function __construct(string $oid)
32
-    {
33
-        $this->_tag = self::TAG_REGISTERED_ID;
34
-        $this->_oid = $oid;
35
-    }
26
+	/**
27
+	 * Constructor.
28
+	 *
29
+	 * @param string $oid OID in dotted format
30
+	 */
31
+	public function __construct(string $oid)
32
+	{
33
+		$this->_tag = self::TAG_REGISTERED_ID;
34
+		$this->_oid = $oid;
35
+	}
36 36
 
37
-    /**
38
-     * {@inheritdoc}
39
-     *
40
-     * @return self
41
-     */
42
-    public static function fromChosenASN1(UnspecifiedType $el): GeneralName
43
-    {
44
-        return new self($el->asObjectIdentifier()->oid());
45
-    }
37
+	/**
38
+	 * {@inheritdoc}
39
+	 *
40
+	 * @return self
41
+	 */
42
+	public static function fromChosenASN1(UnspecifiedType $el): GeneralName
43
+	{
44
+		return new self($el->asObjectIdentifier()->oid());
45
+	}
46 46
 
47
-    /**
48
-     * {@inheritdoc}
49
-     */
50
-    public function string(): string
51
-    {
52
-        return $this->_oid;
53
-    }
47
+	/**
48
+	 * {@inheritdoc}
49
+	 */
50
+	public function string(): string
51
+	{
52
+		return $this->_oid;
53
+	}
54 54
 
55
-    /**
56
-     * Get object identifier in dotted format.
57
-     *
58
-     * @return string OID
59
-     */
60
-    public function oid(): string
61
-    {
62
-        return $this->_oid;
63
-    }
55
+	/**
56
+	 * Get object identifier in dotted format.
57
+	 *
58
+	 * @return string OID
59
+	 */
60
+	public function oid(): string
61
+	{
62
+		return $this->_oid;
63
+	}
64 64
 
65
-    /**
66
-     * {@inheritdoc}
67
-     */
68
-    protected function _choiceASN1(): TaggedType
69
-    {
70
-        return new ImplicitlyTaggedType($this->_tag,
71
-            new ObjectIdentifier($this->_oid));
72
-    }
65
+	/**
66
+	 * {@inheritdoc}
67
+	 */
68
+	protected function _choiceASN1(): TaggedType
69
+	{
70
+		return new ImplicitlyTaggedType($this->_tag,
71
+			new ObjectIdentifier($this->_oid));
72
+	}
73 73
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X509\GeneralName;
6 6
 
Please login to merge, or discard this patch.
lib/X509/GeneralName/GeneralNames.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X509\GeneralName;
6 6
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
                 'GeneralNames must have at least one GeneralName.');
52 52
         }
53 53
         $names = array_map(
54
-            function (UnspecifiedType $el) {
54
+            function(UnspecifiedType $el) {
55 55
                 return GeneralName::fromASN1($el->asTagged());
56 56
             }, $seq->elements());
57 57
         return new self(...$names);
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
     public function allOf(int $tag): array
98 98
     {
99 99
         $names = array_filter($this->_names,
100
-            function (GeneralName $name) use ($tag) {
100
+            function(GeneralName $name) use ($tag) {
101 101
                 return $name->tag() === $tag;
102 102
             });
103 103
         return array_values($names);
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
                 'GeneralNames must have at least one GeneralName.');
161 161
         }
162 162
         $elements = array_map(
163
-            function (GeneralName $name) {
163
+            function(GeneralName $name) {
164 164
                 return $name->toASN1();
165 165
             }, $this->_names);
166 166
         return new Sequence(...$elements);
Please login to merge, or discard this patch.
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -18,190 +18,190 @@
 block discarded – undo
18 18
  */
19 19
 class GeneralNames implements \Countable, \IteratorAggregate
20 20
 {
21
-    /**
22
-     * GeneralName objects.
23
-     *
24
-     * @var GeneralName[]
25
-     */
26
-    protected $_names;
27
-
28
-    /**
29
-     * Constructor.
30
-     *
31
-     * @param GeneralName ...$names One or more GeneralName objects
32
-     */
33
-    public function __construct(GeneralName ...$names)
34
-    {
35
-        $this->_names = $names;
36
-    }
37
-
38
-    /**
39
-     * Initialize from ASN.1.
40
-     *
41
-     * @param Sequence $seq
42
-     *
43
-     * @throws \UnexpectedValueException
44
-     *
45
-     * @return self
46
-     */
47
-    public static function fromASN1(Sequence $seq): GeneralNames
48
-    {
49
-        if (!count($seq)) {
50
-            throw new \UnexpectedValueException(
51
-                'GeneralNames must have at least one GeneralName.');
52
-        }
53
-        $names = array_map(
54
-            function (UnspecifiedType $el) {
55
-                return GeneralName::fromASN1($el->asTagged());
56
-            }, $seq->elements());
57
-        return new self(...$names);
58
-    }
59
-
60
-    /**
61
-     * Check whether GeneralNames contains a GeneralName of given type.
62
-     *
63
-     * @param int $tag One of `GeneralName::TAG_*` enumerations
64
-     *
65
-     * @return bool
66
-     */
67
-    public function has(int $tag): bool
68
-    {
69
-        return null !== $this->_findFirst($tag);
70
-    }
71
-
72
-    /**
73
-     * Get first GeneralName of given type.
74
-     *
75
-     * @param int $tag One of `GeneralName::TAG_*` enumerations
76
-     *
77
-     * @throws \OutOfBoundsException
78
-     *
79
-     * @return GeneralName
80
-     */
81
-    public function firstOf(int $tag): GeneralName
82
-    {
83
-        $name = $this->_findFirst($tag);
84
-        if (!$name) {
85
-            throw new \UnexpectedValueException("No GeneralName by tag {$tag}.");
86
-        }
87
-        return $name;
88
-    }
89
-
90
-    /**
91
-     * Get all GeneralName objects of given type.
92
-     *
93
-     * @param int $tag One of `GeneralName::TAG_*` enumerations
94
-     *
95
-     * @return GeneralName[]
96
-     */
97
-    public function allOf(int $tag): array
98
-    {
99
-        $names = array_filter($this->_names,
100
-            function (GeneralName $name) use ($tag) {
101
-                return $name->tag() === $tag;
102
-            });
103
-        return array_values($names);
104
-    }
105
-
106
-    /**
107
-     * Get value of the first 'dNSName' type.
108
-     *
109
-     * @return string
110
-     */
111
-    public function firstDNS(): string
112
-    {
113
-        $gn = $this->firstOf(GeneralName::TAG_DNS_NAME);
114
-        if (!$gn instanceof DNSName) {
115
-            throw new \RuntimeException(
116
-                DNSName::class . ' expected, got ' . get_class($gn));
117
-        }
118
-        return $gn->name();
119
-    }
120
-
121
-    /**
122
-     * Get value of the first 'directoryName' type.
123
-     *
124
-     * @return Name
125
-     */
126
-    public function firstDN(): Name
127
-    {
128
-        $gn = $this->firstOf(GeneralName::TAG_DIRECTORY_NAME);
129
-        if (!$gn instanceof DirectoryName) {
130
-            throw new \RuntimeException(
131
-                DirectoryName::class . ' expected, got ' . get_class($gn));
132
-        }
133
-        return $gn->dn();
134
-    }
135
-
136
-    /**
137
-     * Get value of the first 'uniformResourceIdentifier' type.
138
-     *
139
-     * @return string
140
-     */
141
-    public function firstURI(): string
142
-    {
143
-        $gn = $this->firstOf(GeneralName::TAG_URI);
144
-        if (!$gn instanceof UniformResourceIdentifier) {
145
-            throw new \RuntimeException(
146
-                UniformResourceIdentifier::class . ' expected, got ' . get_class($gn));
147
-        }
148
-        return $gn->uri();
149
-    }
150
-
151
-    /**
152
-     * Generate ASN.1 structure.
153
-     *
154
-     * @return Sequence
155
-     */
156
-    public function toASN1(): Sequence
157
-    {
158
-        if (!count($this->_names)) {
159
-            throw new \LogicException(
160
-                'GeneralNames must have at least one GeneralName.');
161
-        }
162
-        $elements = array_map(
163
-            function (GeneralName $name) {
164
-                return $name->toASN1();
165
-            }, $this->_names);
166
-        return new Sequence(...$elements);
167
-    }
168
-
169
-    /**
170
-     * @see \Countable::count()
171
-     *
172
-     * @return int
173
-     */
174
-    public function count(): int
175
-    {
176
-        return count($this->_names);
177
-    }
178
-
179
-    /**
180
-     * Get iterator for GeneralName objects.
181
-     *
182
-     * @see \IteratorAggregate::getIterator()
183
-     *
184
-     * @return \ArrayIterator
185
-     */
186
-    public function getIterator(): \ArrayIterator
187
-    {
188
-        return new \ArrayIterator($this->_names);
189
-    }
190
-
191
-    /**
192
-     * Find first GeneralName by given tag.
193
-     *
194
-     * @param int $tag
195
-     *
196
-     * @return null|GeneralName
197
-     */
198
-    protected function _findFirst(int $tag): ?GeneralName
199
-    {
200
-        foreach ($this->_names as $name) {
201
-            if ($name->tag() === $tag) {
202
-                return $name;
203
-            }
204
-        }
205
-        return null;
206
-    }
21
+	/**
22
+	 * GeneralName objects.
23
+	 *
24
+	 * @var GeneralName[]
25
+	 */
26
+	protected $_names;
27
+
28
+	/**
29
+	 * Constructor.
30
+	 *
31
+	 * @param GeneralName ...$names One or more GeneralName objects
32
+	 */
33
+	public function __construct(GeneralName ...$names)
34
+	{
35
+		$this->_names = $names;
36
+	}
37
+
38
+	/**
39
+	 * Initialize from ASN.1.
40
+	 *
41
+	 * @param Sequence $seq
42
+	 *
43
+	 * @throws \UnexpectedValueException
44
+	 *
45
+	 * @return self
46
+	 */
47
+	public static function fromASN1(Sequence $seq): GeneralNames
48
+	{
49
+		if (!count($seq)) {
50
+			throw new \UnexpectedValueException(
51
+				'GeneralNames must have at least one GeneralName.');
52
+		}
53
+		$names = array_map(
54
+			function (UnspecifiedType $el) {
55
+				return GeneralName::fromASN1($el->asTagged());
56
+			}, $seq->elements());
57
+		return new self(...$names);
58
+	}
59
+
60
+	/**
61
+	 * Check whether GeneralNames contains a GeneralName of given type.
62
+	 *
63
+	 * @param int $tag One of `GeneralName::TAG_*` enumerations
64
+	 *
65
+	 * @return bool
66
+	 */
67
+	public function has(int $tag): bool
68
+	{
69
+		return null !== $this->_findFirst($tag);
70
+	}
71
+
72
+	/**
73
+	 * Get first GeneralName of given type.
74
+	 *
75
+	 * @param int $tag One of `GeneralName::TAG_*` enumerations
76
+	 *
77
+	 * @throws \OutOfBoundsException
78
+	 *
79
+	 * @return GeneralName
80
+	 */
81
+	public function firstOf(int $tag): GeneralName
82
+	{
83
+		$name = $this->_findFirst($tag);
84
+		if (!$name) {
85
+			throw new \UnexpectedValueException("No GeneralName by tag {$tag}.");
86
+		}
87
+		return $name;
88
+	}
89
+
90
+	/**
91
+	 * Get all GeneralName objects of given type.
92
+	 *
93
+	 * @param int $tag One of `GeneralName::TAG_*` enumerations
94
+	 *
95
+	 * @return GeneralName[]
96
+	 */
97
+	public function allOf(int $tag): array
98
+	{
99
+		$names = array_filter($this->_names,
100
+			function (GeneralName $name) use ($tag) {
101
+				return $name->tag() === $tag;
102
+			});
103
+		return array_values($names);
104
+	}
105
+
106
+	/**
107
+	 * Get value of the first 'dNSName' type.
108
+	 *
109
+	 * @return string
110
+	 */
111
+	public function firstDNS(): string
112
+	{
113
+		$gn = $this->firstOf(GeneralName::TAG_DNS_NAME);
114
+		if (!$gn instanceof DNSName) {
115
+			throw new \RuntimeException(
116
+				DNSName::class . ' expected, got ' . get_class($gn));
117
+		}
118
+		return $gn->name();
119
+	}
120
+
121
+	/**
122
+	 * Get value of the first 'directoryName' type.
123
+	 *
124
+	 * @return Name
125
+	 */
126
+	public function firstDN(): Name
127
+	{
128
+		$gn = $this->firstOf(GeneralName::TAG_DIRECTORY_NAME);
129
+		if (!$gn instanceof DirectoryName) {
130
+			throw new \RuntimeException(
131
+				DirectoryName::class . ' expected, got ' . get_class($gn));
132
+		}
133
+		return $gn->dn();
134
+	}
135
+
136
+	/**
137
+	 * Get value of the first 'uniformResourceIdentifier' type.
138
+	 *
139
+	 * @return string
140
+	 */
141
+	public function firstURI(): string
142
+	{
143
+		$gn = $this->firstOf(GeneralName::TAG_URI);
144
+		if (!$gn instanceof UniformResourceIdentifier) {
145
+			throw new \RuntimeException(
146
+				UniformResourceIdentifier::class . ' expected, got ' . get_class($gn));
147
+		}
148
+		return $gn->uri();
149
+	}
150
+
151
+	/**
152
+	 * Generate ASN.1 structure.
153
+	 *
154
+	 * @return Sequence
155
+	 */
156
+	public function toASN1(): Sequence
157
+	{
158
+		if (!count($this->_names)) {
159
+			throw new \LogicException(
160
+				'GeneralNames must have at least one GeneralName.');
161
+		}
162
+		$elements = array_map(
163
+			function (GeneralName $name) {
164
+				return $name->toASN1();
165
+			}, $this->_names);
166
+		return new Sequence(...$elements);
167
+	}
168
+
169
+	/**
170
+	 * @see \Countable::count()
171
+	 *
172
+	 * @return int
173
+	 */
174
+	public function count(): int
175
+	{
176
+		return count($this->_names);
177
+	}
178
+
179
+	/**
180
+	 * Get iterator for GeneralName objects.
181
+	 *
182
+	 * @see \IteratorAggregate::getIterator()
183
+	 *
184
+	 * @return \ArrayIterator
185
+	 */
186
+	public function getIterator(): \ArrayIterator
187
+	{
188
+		return new \ArrayIterator($this->_names);
189
+	}
190
+
191
+	/**
192
+	 * Find first GeneralName by given tag.
193
+	 *
194
+	 * @param int $tag
195
+	 *
196
+	 * @return null|GeneralName
197
+	 */
198
+	protected function _findFirst(int $tag): ?GeneralName
199
+	{
200
+		foreach ($this->_names as $name) {
201
+			if ($name->tag() === $tag) {
202
+				return $name;
203
+			}
204
+		}
205
+		return null;
206
+	}
207 207
 }
Please login to merge, or discard this patch.
lib/X509/GeneralName/OtherName.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -19,81 +19,81 @@
 block discarded – undo
19 19
  */
20 20
 class OtherName extends GeneralName
21 21
 {
22
-    /**
23
-     * Type OID.
24
-     *
25
-     * @var string
26
-     */
27
-    protected $_type;
22
+	/**
23
+	 * Type OID.
24
+	 *
25
+	 * @var string
26
+	 */
27
+	protected $_type;
28 28
 
29
-    /**
30
-     * Value.
31
-     *
32
-     * @var Element
33
-     */
34
-    protected $_element;
29
+	/**
30
+	 * Value.
31
+	 *
32
+	 * @var Element
33
+	 */
34
+	protected $_element;
35 35
 
36
-    /**
37
-     * Constructor.
38
-     *
39
-     * @param string  $type_id OID
40
-     * @param Element $el
41
-     */
42
-    public function __construct(string $type_id, Element $el)
43
-    {
44
-        $this->_tag = self::TAG_OTHER_NAME;
45
-        $this->_type = $type_id;
46
-        $this->_element = $el;
47
-    }
36
+	/**
37
+	 * Constructor.
38
+	 *
39
+	 * @param string  $type_id OID
40
+	 * @param Element $el
41
+	 */
42
+	public function __construct(string $type_id, Element $el)
43
+	{
44
+		$this->_tag = self::TAG_OTHER_NAME;
45
+		$this->_type = $type_id;
46
+		$this->_element = $el;
47
+	}
48 48
 
49
-    /**
50
-     * {@inheritdoc}
51
-     *
52
-     * @return self
53
-     */
54
-    public static function fromChosenASN1(UnspecifiedType $el): GeneralName
55
-    {
56
-        $seq = $el->asSequence();
57
-        $type_id = $seq->at(0)->asObjectIdentifier()->oid();
58
-        $value = $seq->getTagged(0)->asExplicit()->asElement();
59
-        return new self($type_id, $value);
60
-    }
49
+	/**
50
+	 * {@inheritdoc}
51
+	 *
52
+	 * @return self
53
+	 */
54
+	public static function fromChosenASN1(UnspecifiedType $el): GeneralName
55
+	{
56
+		$seq = $el->asSequence();
57
+		$type_id = $seq->at(0)->asObjectIdentifier()->oid();
58
+		$value = $seq->getTagged(0)->asExplicit()->asElement();
59
+		return new self($type_id, $value);
60
+	}
61 61
 
62
-    /**
63
-     * {@inheritdoc}
64
-     */
65
-    public function string(): string
66
-    {
67
-        return $this->_type . '/#' . bin2hex($this->_element->toDER());
68
-    }
62
+	/**
63
+	 * {@inheritdoc}
64
+	 */
65
+	public function string(): string
66
+	{
67
+		return $this->_type . '/#' . bin2hex($this->_element->toDER());
68
+	}
69 69
 
70
-    /**
71
-     * Get type OID.
72
-     *
73
-     * @return string
74
-     */
75
-    public function type(): string
76
-    {
77
-        return $this->_type;
78
-    }
70
+	/**
71
+	 * Get type OID.
72
+	 *
73
+	 * @return string
74
+	 */
75
+	public function type(): string
76
+	{
77
+		return $this->_type;
78
+	}
79 79
 
80
-    /**
81
-     * Get value element.
82
-     *
83
-     * @return Element
84
-     */
85
-    public function value(): Element
86
-    {
87
-        return $this->_element;
88
-    }
80
+	/**
81
+	 * Get value element.
82
+	 *
83
+	 * @return Element
84
+	 */
85
+	public function value(): Element
86
+	{
87
+		return $this->_element;
88
+	}
89 89
 
90
-    /**
91
-     * {@inheritdoc}
92
-     */
93
-    protected function _choiceASN1(): TaggedType
94
-    {
95
-        return new ImplicitlyTaggedType($this->_tag,
96
-            new Sequence(new ObjectIdentifier($this->_type),
97
-                new ExplicitlyTaggedType(0, $this->_element)));
98
-    }
90
+	/**
91
+	 * {@inheritdoc}
92
+	 */
93
+	protected function _choiceASN1(): TaggedType
94
+	{
95
+		return new ImplicitlyTaggedType($this->_tag,
96
+			new Sequence(new ObjectIdentifier($this->_type),
97
+				new ExplicitlyTaggedType(0, $this->_element)));
98
+	}
99 99
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X509\GeneralName;
6 6
 
Please login to merge, or discard this patch.
lib/X509/GeneralName/UniformResourceIdentifier.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -17,57 +17,57 @@
 block discarded – undo
17 17
  */
18 18
 class UniformResourceIdentifier extends GeneralName
19 19
 {
20
-    /**
21
-     * URI.
22
-     *
23
-     * @var string
24
-     */
25
-    protected $_uri;
20
+	/**
21
+	 * URI.
22
+	 *
23
+	 * @var string
24
+	 */
25
+	protected $_uri;
26 26
 
27
-    /**
28
-     * Constructor.
29
-     *
30
-     * @param string $uri
31
-     */
32
-    public function __construct(string $uri)
33
-    {
34
-        $this->_tag = self::TAG_URI;
35
-        $this->_uri = $uri;
36
-    }
27
+	/**
28
+	 * Constructor.
29
+	 *
30
+	 * @param string $uri
31
+	 */
32
+	public function __construct(string $uri)
33
+	{
34
+		$this->_tag = self::TAG_URI;
35
+		$this->_uri = $uri;
36
+	}
37 37
 
38
-    /**
39
-     * {@inheritdoc}
40
-     *
41
-     * @return self
42
-     */
43
-    public static function fromChosenASN1(UnspecifiedType $el): GeneralName
44
-    {
45
-        return new self($el->asIA5String()->string());
46
-    }
38
+	/**
39
+	 * {@inheritdoc}
40
+	 *
41
+	 * @return self
42
+	 */
43
+	public static function fromChosenASN1(UnspecifiedType $el): GeneralName
44
+	{
45
+		return new self($el->asIA5String()->string());
46
+	}
47 47
 
48
-    /**
49
-     * {@inheritdoc}
50
-     */
51
-    public function string(): string
52
-    {
53
-        return $this->_uri;
54
-    }
48
+	/**
49
+	 * {@inheritdoc}
50
+	 */
51
+	public function string(): string
52
+	{
53
+		return $this->_uri;
54
+	}
55 55
 
56
-    /**
57
-     * Get URI.
58
-     *
59
-     * @return string
60
-     */
61
-    public function uri(): string
62
-    {
63
-        return $this->_uri;
64
-    }
56
+	/**
57
+	 * Get URI.
58
+	 *
59
+	 * @return string
60
+	 */
61
+	public function uri(): string
62
+	{
63
+		return $this->_uri;
64
+	}
65 65
 
66
-    /**
67
-     * {@inheritdoc}
68
-     */
69
-    protected function _choiceASN1(): TaggedType
70
-    {
71
-        return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_uri));
72
-    }
66
+	/**
67
+	 * {@inheritdoc}
68
+	 */
69
+	protected function _choiceASN1(): TaggedType
70
+	{
71
+		return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_uri));
72
+	}
73 73
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X509\GeneralName;
6 6
 
Please login to merge, or discard this patch.
lib/X509/GeneralName/GeneralName.php 3 patches
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -15,151 +15,151 @@
 block discarded – undo
15 15
  */
16 16
 abstract class GeneralName
17 17
 {
18
-    // GeneralName CHOICE tags
19
-    const TAG_OTHER_NAME = 0;
20
-    const TAG_RFC822_NAME = 1;
21
-    const TAG_DNS_NAME = 2;
22
-    const TAG_X400_ADDRESS = 3;
23
-    const TAG_DIRECTORY_NAME = 4;
24
-    const TAG_EDI_PARTY_NAME = 5;
25
-    const TAG_URI = 6;
26
-    const TAG_IP_ADDRESS = 7;
27
-    const TAG_REGISTERED_ID = 8;
18
+	// GeneralName CHOICE tags
19
+	const TAG_OTHER_NAME = 0;
20
+	const TAG_RFC822_NAME = 1;
21
+	const TAG_DNS_NAME = 2;
22
+	const TAG_X400_ADDRESS = 3;
23
+	const TAG_DIRECTORY_NAME = 4;
24
+	const TAG_EDI_PARTY_NAME = 5;
25
+	const TAG_URI = 6;
26
+	const TAG_IP_ADDRESS = 7;
27
+	const TAG_REGISTERED_ID = 8;
28 28
 
29
-    /**
30
-     * Chosen tag.
31
-     *
32
-     * @var int
33
-     */
34
-    protected $_tag;
29
+	/**
30
+	 * Chosen tag.
31
+	 *
32
+	 * @var int
33
+	 */
34
+	protected $_tag;
35 35
 
36
-    /**
37
-     * Get general name as a string.
38
-     *
39
-     * @return string
40
-     */
41
-    public function __toString(): string
42
-    {
43
-        return $this->string();
44
-    }
36
+	/**
37
+	 * Get general name as a string.
38
+	 *
39
+	 * @return string
40
+	 */
41
+	public function __toString(): string
42
+	{
43
+		return $this->string();
44
+	}
45 45
 
46
-    /**
47
-     * Get string value of the type.
48
-     *
49
-     * @return string
50
-     */
51
-    abstract public function string(): string;
46
+	/**
47
+	 * Get string value of the type.
48
+	 *
49
+	 * @return string
50
+	 */
51
+	abstract public function string(): string;
52 52
 
53
-    /**
54
-     * Initialize concrete object from the chosen ASN.1 element.
55
-     *
56
-     * @param UnspecifiedType $el
57
-     *
58
-     * @return self
59
-     */
60
-    public static function fromChosenASN1(UnspecifiedType $el): GeneralName
61
-    {
62
-        throw new \BadMethodCallException(
63
-            __FUNCTION__ . ' must be implemented in the derived class.');
64
-    }
53
+	/**
54
+	 * Initialize concrete object from the chosen ASN.1 element.
55
+	 *
56
+	 * @param UnspecifiedType $el
57
+	 *
58
+	 * @return self
59
+	 */
60
+	public static function fromChosenASN1(UnspecifiedType $el): GeneralName
61
+	{
62
+		throw new \BadMethodCallException(
63
+			__FUNCTION__ . ' must be implemented in the derived class.');
64
+	}
65 65
 
66
-    /**
67
-     * Initialize from ASN.1.
68
-     *
69
-     * @param TaggedType $el
70
-     *
71
-     * @throws \UnexpectedValueException
72
-     *
73
-     * @return self
74
-     */
75
-    public static function fromASN1(TaggedType $el): self
76
-    {
77
-        switch ($el->tag()) {
78
-            // otherName
79
-            case self::TAG_OTHER_NAME:
80
-                return OtherName::fromChosenASN1(
81
-                    $el->asImplicit(Element::TYPE_SEQUENCE));
82
-            // rfc822Name
83
-            case self::TAG_RFC822_NAME:
84
-                return RFC822Name::fromChosenASN1(
85
-                    $el->asImplicit(Element::TYPE_IA5_STRING));
86
-            // dNSName
87
-            case self::TAG_DNS_NAME:
88
-                return DNSName::fromChosenASN1(
89
-                    $el->asImplicit(Element::TYPE_IA5_STRING));
90
-            // x400Address
91
-            case self::TAG_X400_ADDRESS:
92
-                return X400Address::fromChosenASN1(
93
-                    $el->asImplicit(Element::TYPE_SEQUENCE));
94
-            // directoryName
95
-            case self::TAG_DIRECTORY_NAME:
96
-                // because Name is a CHOICE, albeit having only one option,
97
-                // explicit tagging must be used
98
-                // (see X.680 07/2002 30.6.c)
99
-                return DirectoryName::fromChosenASN1($el->asExplicit());
100
-            // ediPartyName
101
-            case self::TAG_EDI_PARTY_NAME:
102
-                return EDIPartyName::fromChosenASN1(
103
-                    $el->asImplicit(Element::TYPE_SEQUENCE));
104
-            // uniformResourceIdentifier
105
-            case self::TAG_URI:
106
-                return UniformResourceIdentifier::fromChosenASN1(
107
-                    $el->asImplicit(Element::TYPE_IA5_STRING));
108
-            // iPAddress
109
-            case self::TAG_IP_ADDRESS:
110
-                return IPAddress::fromChosenASN1(
111
-                    $el->asImplicit(Element::TYPE_OCTET_STRING));
112
-            // registeredID
113
-            case self::TAG_REGISTERED_ID:
114
-                return RegisteredID::fromChosenASN1(
115
-                    $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER));
116
-        }
117
-        throw new \UnexpectedValueException(
118
-            'GeneralName type ' . $el->tag() . ' not supported.');
119
-    }
66
+	/**
67
+	 * Initialize from ASN.1.
68
+	 *
69
+	 * @param TaggedType $el
70
+	 *
71
+	 * @throws \UnexpectedValueException
72
+	 *
73
+	 * @return self
74
+	 */
75
+	public static function fromASN1(TaggedType $el): self
76
+	{
77
+		switch ($el->tag()) {
78
+			// otherName
79
+			case self::TAG_OTHER_NAME:
80
+				return OtherName::fromChosenASN1(
81
+					$el->asImplicit(Element::TYPE_SEQUENCE));
82
+			// rfc822Name
83
+			case self::TAG_RFC822_NAME:
84
+				return RFC822Name::fromChosenASN1(
85
+					$el->asImplicit(Element::TYPE_IA5_STRING));
86
+			// dNSName
87
+			case self::TAG_DNS_NAME:
88
+				return DNSName::fromChosenASN1(
89
+					$el->asImplicit(Element::TYPE_IA5_STRING));
90
+			// x400Address
91
+			case self::TAG_X400_ADDRESS:
92
+				return X400Address::fromChosenASN1(
93
+					$el->asImplicit(Element::TYPE_SEQUENCE));
94
+			// directoryName
95
+			case self::TAG_DIRECTORY_NAME:
96
+				// because Name is a CHOICE, albeit having only one option,
97
+				// explicit tagging must be used
98
+				// (see X.680 07/2002 30.6.c)
99
+				return DirectoryName::fromChosenASN1($el->asExplicit());
100
+			// ediPartyName
101
+			case self::TAG_EDI_PARTY_NAME:
102
+				return EDIPartyName::fromChosenASN1(
103
+					$el->asImplicit(Element::TYPE_SEQUENCE));
104
+			// uniformResourceIdentifier
105
+			case self::TAG_URI:
106
+				return UniformResourceIdentifier::fromChosenASN1(
107
+					$el->asImplicit(Element::TYPE_IA5_STRING));
108
+			// iPAddress
109
+			case self::TAG_IP_ADDRESS:
110
+				return IPAddress::fromChosenASN1(
111
+					$el->asImplicit(Element::TYPE_OCTET_STRING));
112
+			// registeredID
113
+			case self::TAG_REGISTERED_ID:
114
+				return RegisteredID::fromChosenASN1(
115
+					$el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER));
116
+		}
117
+		throw new \UnexpectedValueException(
118
+			'GeneralName type ' . $el->tag() . ' not supported.');
119
+	}
120 120
 
121
-    /**
122
-     * Get type tag.
123
-     *
124
-     * @return int
125
-     */
126
-    public function tag(): int
127
-    {
128
-        return $this->_tag;
129
-    }
121
+	/**
122
+	 * Get type tag.
123
+	 *
124
+	 * @return int
125
+	 */
126
+	public function tag(): int
127
+	{
128
+		return $this->_tag;
129
+	}
130 130
 
131
-    /**
132
-     * Generate ASN.1 element.
133
-     *
134
-     * @return Element
135
-     */
136
-    public function toASN1(): Element
137
-    {
138
-        return $this->_choiceASN1();
139
-    }
131
+	/**
132
+	 * Generate ASN.1 element.
133
+	 *
134
+	 * @return Element
135
+	 */
136
+	public function toASN1(): Element
137
+	{
138
+		return $this->_choiceASN1();
139
+	}
140 140
 
141
-    /**
142
-     * Check whether GeneralName is equal to other.
143
-     *
144
-     * @param GeneralName $other GeneralName to compare to
145
-     *
146
-     * @return bool True if names are equal
147
-     */
148
-    public function equals(GeneralName $other): bool
149
-    {
150
-        if ($this->_tag !== $other->_tag) {
151
-            return false;
152
-        }
153
-        if ($this->_choiceASN1()->toDER() !== $other->_choiceASN1()->toDER()) {
154
-            return false;
155
-        }
156
-        return true;
157
-    }
141
+	/**
142
+	 * Check whether GeneralName is equal to other.
143
+	 *
144
+	 * @param GeneralName $other GeneralName to compare to
145
+	 *
146
+	 * @return bool True if names are equal
147
+	 */
148
+	public function equals(GeneralName $other): bool
149
+	{
150
+		if ($this->_tag !== $other->_tag) {
151
+			return false;
152
+		}
153
+		if ($this->_choiceASN1()->toDER() !== $other->_choiceASN1()->toDER()) {
154
+			return false;
155
+		}
156
+		return true;
157
+	}
158 158
 
159
-    /**
160
-     * Get ASN.1 value in GeneralName CHOICE context.
161
-     *
162
-     * @return TaggedType
163
-     */
164
-    abstract protected function _choiceASN1(): TaggedType;
159
+	/**
160
+	 * Get ASN.1 value in GeneralName CHOICE context.
161
+	 *
162
+	 * @return TaggedType
163
+	 */
164
+	abstract protected function _choiceASN1(): TaggedType;
165 165
 }
Please login to merge, or discard this patch.
Switch Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -76,43 +76,43 @@
 block discarded – undo
76 76
     {
77 77
         switch ($el->tag()) {
78 78
             // otherName
79
-            case self::TAG_OTHER_NAME:
80
-                return OtherName::fromChosenASN1(
81
-                    $el->asImplicit(Element::TYPE_SEQUENCE));
82
-            // rfc822Name
83
-            case self::TAG_RFC822_NAME:
84
-                return RFC822Name::fromChosenASN1(
85
-                    $el->asImplicit(Element::TYPE_IA5_STRING));
86
-            // dNSName
87
-            case self::TAG_DNS_NAME:
88
-                return DNSName::fromChosenASN1(
89
-                    $el->asImplicit(Element::TYPE_IA5_STRING));
90
-            // x400Address
91
-            case self::TAG_X400_ADDRESS:
92
-                return X400Address::fromChosenASN1(
93
-                    $el->asImplicit(Element::TYPE_SEQUENCE));
94
-            // directoryName
95
-            case self::TAG_DIRECTORY_NAME:
96
-                // because Name is a CHOICE, albeit having only one option,
97
-                // explicit tagging must be used
98
-                // (see X.680 07/2002 30.6.c)
99
-                return DirectoryName::fromChosenASN1($el->asExplicit());
100
-            // ediPartyName
101
-            case self::TAG_EDI_PARTY_NAME:
102
-                return EDIPartyName::fromChosenASN1(
103
-                    $el->asImplicit(Element::TYPE_SEQUENCE));
104
-            // uniformResourceIdentifier
105
-            case self::TAG_URI:
106
-                return UniformResourceIdentifier::fromChosenASN1(
107
-                    $el->asImplicit(Element::TYPE_IA5_STRING));
108
-            // iPAddress
109
-            case self::TAG_IP_ADDRESS:
110
-                return IPAddress::fromChosenASN1(
111
-                    $el->asImplicit(Element::TYPE_OCTET_STRING));
112
-            // registeredID
113
-            case self::TAG_REGISTERED_ID:
114
-                return RegisteredID::fromChosenASN1(
115
-                    $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER));
79
+        case self::TAG_OTHER_NAME:
80
+            return OtherName::fromChosenASN1(
81
+                $el->asImplicit(Element::TYPE_SEQUENCE));
82
+        // rfc822Name
83
+        case self::TAG_RFC822_NAME:
84
+            return RFC822Name::fromChosenASN1(
85
+                $el->asImplicit(Element::TYPE_IA5_STRING));
86
+        // dNSName
87
+        case self::TAG_DNS_NAME:
88
+            return DNSName::fromChosenASN1(
89
+                $el->asImplicit(Element::TYPE_IA5_STRING));
90
+        // x400Address
91
+        case self::TAG_X400_ADDRESS:
92
+            return X400Address::fromChosenASN1(
93
+                $el->asImplicit(Element::TYPE_SEQUENCE));
94
+        // directoryName
95
+        case self::TAG_DIRECTORY_NAME:
96
+            // because Name is a CHOICE, albeit having only one option,
97
+            // explicit tagging must be used
98
+            // (see X.680 07/2002 30.6.c)
99
+            return DirectoryName::fromChosenASN1($el->asExplicit());
100
+        // ediPartyName
101
+        case self::TAG_EDI_PARTY_NAME:
102
+            return EDIPartyName::fromChosenASN1(
103
+                $el->asImplicit(Element::TYPE_SEQUENCE));
104
+        // uniformResourceIdentifier
105
+        case self::TAG_URI:
106
+            return UniformResourceIdentifier::fromChosenASN1(
107
+                $el->asImplicit(Element::TYPE_IA5_STRING));
108
+        // iPAddress
109
+        case self::TAG_IP_ADDRESS:
110
+            return IPAddress::fromChosenASN1(
111
+                $el->asImplicit(Element::TYPE_OCTET_STRING));
112
+        // registeredID
113
+        case self::TAG_REGISTERED_ID:
114
+            return RegisteredID::fromChosenASN1(
115
+                $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER));
116 116
         }
117 117
         throw new \UnexpectedValueException(
118 118
             'GeneralName type ' . $el->tag() . ' not supported.');
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X509\GeneralName;
6 6
 
Please login to merge, or discard this patch.
lib/X509/GeneralName/EDIPartyName.php 2 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -19,44 +19,44 @@
 block discarded – undo
19 19
  */
20 20
 class EDIPartyName extends GeneralName
21 21
 {
22
-    /**
23
-     * @var \Sop\ASN1\Element
24
-     */
25
-    protected $_element;
26
-
27
-    /**
28
-     * Constructor.
29
-     */
30
-    protected function __construct()
31
-    {
32
-        $this->_tag = self::TAG_EDI_PARTY_NAME;
33
-    }
34
-
35
-    /**
36
-     * {@inheritdoc}
37
-     *
38
-     * @return self
39
-     */
40
-    public static function fromChosenASN1(UnspecifiedType $el): GeneralName
41
-    {
42
-        $obj = new self();
43
-        $obj->_element = $el->asSequence();
44
-        return $obj;
45
-    }
46
-
47
-    /**
48
-     * {@inheritdoc}
49
-     */
50
-    public function string(): string
51
-    {
52
-        return bin2hex($this->_element->toDER());
53
-    }
54
-
55
-    /**
56
-     * {@inheritdoc}
57
-     */
58
-    protected function _choiceASN1(): TaggedType
59
-    {
60
-        return new ImplicitlyTaggedType($this->_tag, $this->_element);
61
-    }
22
+	/**
23
+	 * @var \Sop\ASN1\Element
24
+	 */
25
+	protected $_element;
26
+
27
+	/**
28
+	 * Constructor.
29
+	 */
30
+	protected function __construct()
31
+	{
32
+		$this->_tag = self::TAG_EDI_PARTY_NAME;
33
+	}
34
+
35
+	/**
36
+	 * {@inheritdoc}
37
+	 *
38
+	 * @return self
39
+	 */
40
+	public static function fromChosenASN1(UnspecifiedType $el): GeneralName
41
+	{
42
+		$obj = new self();
43
+		$obj->_element = $el->asSequence();
44
+		return $obj;
45
+	}
46
+
47
+	/**
48
+	 * {@inheritdoc}
49
+	 */
50
+	public function string(): string
51
+	{
52
+		return bin2hex($this->_element->toDER());
53
+	}
54
+
55
+	/**
56
+	 * {@inheritdoc}
57
+	 */
58
+	protected function _choiceASN1(): TaggedType
59
+	{
60
+		return new ImplicitlyTaggedType($this->_tag, $this->_element);
61
+	}
62 62
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X509\GeneralName;
6 6
 
Please login to merge, or discard this patch.
lib/X509/GeneralName/DNSName.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -16,57 +16,57 @@
 block discarded – undo
16 16
  */
17 17
 class DNSName extends GeneralName
18 18
 {
19
-    /**
20
-     * DNS name.
21
-     *
22
-     * @var string
23
-     */
24
-    protected $_name;
19
+	/**
20
+	 * DNS name.
21
+	 *
22
+	 * @var string
23
+	 */
24
+	protected $_name;
25 25
 
26
-    /**
27
-     * Constructor.
28
-     *
29
-     * @param string $name Domain name
30
-     */
31
-    public function __construct(string $name)
32
-    {
33
-        $this->_tag = self::TAG_DNS_NAME;
34
-        $this->_name = $name;
35
-    }
26
+	/**
27
+	 * Constructor.
28
+	 *
29
+	 * @param string $name Domain name
30
+	 */
31
+	public function __construct(string $name)
32
+	{
33
+		$this->_tag = self::TAG_DNS_NAME;
34
+		$this->_name = $name;
35
+	}
36 36
 
37
-    /**
38
-     * {@inheritdoc}
39
-     *
40
-     * @return self
41
-     */
42
-    public static function fromChosenASN1(UnspecifiedType $el): GeneralName
43
-    {
44
-        return new self($el->asIA5String()->string());
45
-    }
37
+	/**
38
+	 * {@inheritdoc}
39
+	 *
40
+	 * @return self
41
+	 */
42
+	public static function fromChosenASN1(UnspecifiedType $el): GeneralName
43
+	{
44
+		return new self($el->asIA5String()->string());
45
+	}
46 46
 
47
-    /**
48
-     * {@inheritdoc}
49
-     */
50
-    public function string(): string
51
-    {
52
-        return $this->_name;
53
-    }
47
+	/**
48
+	 * {@inheritdoc}
49
+	 */
50
+	public function string(): string
51
+	{
52
+		return $this->_name;
53
+	}
54 54
 
55
-    /**
56
-     * Get DNS name.
57
-     *
58
-     * @return string
59
-     */
60
-    public function name(): string
61
-    {
62
-        return $this->_name;
63
-    }
55
+	/**
56
+	 * Get DNS name.
57
+	 *
58
+	 * @return string
59
+	 */
60
+	public function name(): string
61
+	{
62
+		return $this->_name;
63
+	}
64 64
 
65
-    /**
66
-     * {@inheritdoc}
67
-     */
68
-    protected function _choiceASN1(): TaggedType
69
-    {
70
-        return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_name));
71
-    }
65
+	/**
66
+	 * {@inheritdoc}
67
+	 */
68
+	protected function _choiceASN1(): TaggedType
69
+	{
70
+		return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_name));
71
+	}
72 72
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\X509\GeneralName;
6 6
 
Please login to merge, or discard this patch.