Rev 618 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 618 | Rev 728 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OidDerConverter.class.php, Version 1.1; Based on version 1.11 of oid.c |
4 | * OidDerConverter.class.php, Version 1.1; Based on version 1.11 of oid.c |
5 | * Copyright 2014-2015 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2014-2022 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with the License. |
8 | * you may not use this file except in compliance with the License. |
9 | * You may obtain a copy of the License at |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
Line 42... | Line 42... | ||
42 | 42 | ||
43 | return $out; |
43 | return $out; |
44 | } |
44 | } |
45 | 45 | ||
46 | /** |
46 | /** |
47 | * @return string Outputs .<oid> for an absolute OID and <oid> for a relative OID. |
47 | * @return string|false Outputs .<oid> for an absolute OID and <oid> for a relative OID. |
48 | */ |
48 | */ |
49 | public static function derToOID($abBinary, $verbose=false) { |
49 | public static function derToOID($abBinary, $verbose=false) { |
50 | $output_oid = array(); |
50 | $output_oid = array(); |
51 | $output_absolute = true; |
51 | $output_absolute = true; |
52 | 52 | ||
Line 70... | Line 70... | ||
70 | $lengthbyte_pos = 0; |
70 | $lengthbyte_pos = 0; |
71 | $lengthfinished = false; |
71 | $lengthfinished = false; |
72 | 72 | ||
73 | $arcBeginning = true; |
73 | $arcBeginning = true; |
74 | 74 | ||
- | 75 | $isRelative = null; // to avoid that phpstan complains |
|
- | 76 | ||
75 | foreach ($abBinary as $nn => &$pb) { |
77 | foreach ($abBinary as $nn => &$pb) { |
76 | if ($part == 0) { // Class Tag |
78 | if ($part == 0) { // Class Tag |
77 | // Leading octet |
79 | // Leading octet |
78 | // Bit 7 / Bit 6 = Universal (00), Application (01), Context (10), Private(11) |
80 | // Bit 7 / Bit 6 = Universal (00), Application (01), Context (10), Private(11) |
79 | // Bit 5 = Primitive (0), Constructed (1) |
81 | // Bit 5 = Primitive (0), Constructed (1) |
Line 187... | Line 189... | ||
187 | 189 | ||
188 | if (($pb & 0x80) != 0) { |
190 | if (($pb & 0x80) != 0) { |
189 | // 2.48 and up => 2+ octets |
191 | // 2.48 and up => 2+ octets |
190 | // Output in "part 3" |
192 | // Output in "part 3" |
191 | 193 | ||
192 | if ($arcBeginning && ($pb == 0x80)) { |
194 | if ($pb == 0x80) { |
193 | if ($verbose) fprintf(STDERR, "Encoding error. Illegal 0x80 paddings. (See Rec. ITU-T X.690, clause 8.19.2)\n"); |
195 | if ($verbose) fprintf(STDERR, "Encoding error. Illegal 0x80 paddings. (See Rec. ITU-T X.690, clause 8.19.2)\n"); |
194 | return false; |
196 | return false; |
195 | } else { |
197 | } else { |
196 | $arcBeginning = false; |
198 | $arcBeginning = false; |
197 | } |
199 | } |
Line 350... | Line 352... | ||
350 | 352 | ||
351 | $output[] = 0x80 + $lengthCount; |
353 | $output[] = 0x80 + $lengthCount; |
352 | 354 | ||
353 | $nBinaryWork = $nBinary; |
355 | $nBinaryWork = $nBinary; |
354 | do { |
356 | do { |
355 | $output[] = nBinaryWork & 0xFF; |
357 | $output[] = $nBinaryWork & 0xFF; |
356 | $nBinaryWork /= 0x100; |
358 | $nBinaryWork /= 0x100; |
357 | } while ($nBinaryWork > 0); |
359 | } while ($nBinaryWork > 0); |
358 | } |
360 | } |
359 | 361 | ||
360 | foreach ($abBinary as $b) { |
362 | foreach ($abBinary as $b) { |