Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/vendor/fgrosse/phpasn1/README.md
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
PHPASN1
2
+
=======
3
+
4
+
[](https://github.com/fgrosse/PHPASN1/actions/workflows/phpunit.yml)
5
+
[](https://travis-ci.org/fgrosse/PHPASN1)
6
+
[](https://coveralls.io/github/fgrosse/PHPASN1?branch=master)
7
+
8
+
[](https://packagist.org/packages/fgrosse/phpasn1)
9
+
[](https://packagist.org/packages/fgrosse/phpasn1)
10
+
[](https://packagist.org/packages/fgrosse/phpasn1)
11
+
[](https://packagist.org/packages/fgrosse/phpasn1)
12
+
13
+
---
14
+
15
+
<h2><span style="color:red">Notice: This library is no longer actively maintained!</span></h2>
16
+
If you are currently using PHPASN1, this might not be an immediate problem for you, since this library was always rather stable.
17
+
18
+
However, you are advised to migrate to alternative packages to ensure that your applications remain functional also with newer PHP versions.
19
+
20
+
---
21
+
22
+
A PHP Framework that allows you to encode and decode arbitrary [ASN.1][3] structures
23
+
using the [ITU-T X.690 Encoding Rules][4].
24
+
This encoding is very frequently used in [X.509 PKI environments][5] or the communication between heterogeneous computer systems.
25
+
26
+
The API allows you to encode ASN.1 structures to create binary data such as certificate
27
+
signing requests (CSR), X.509 certificates or certificate revocation lists (CRL).
28
+
PHPASN1 can also read [BER encoded][6] binary data into separate PHP objects that can be manipulated by the user and reencoded afterwards.
29
+
30
+
The **changelog** can now be found at [CHANGELOG.md](CHANGELOG.md).
31
+
32
+
## Dependencies
33
+
34
+
PHPASN1 requires at least `PHP 7.0` and either the `gmp` or `bcmath` extension.
35
+
Support for older PHP versions (i.e. PHP 5.6) was dropped starting with `v2.0`.
36
+
If you must use an outdated PHP version consider using [PHPASN v1.5][13].
37
+
38
+
For the loading of object identifier names directly from the web [curl][7] is used.
39
+
40
+
## Installation
41
+
42
+
The preferred way to install this library is to rely on [Composer][2]:
43
+
44
+
```bash
45
+
$ composer require fgrosse/phpasn1
46
+
```
47
+
48
+
## Usage
49
+
50
+
### Encoding ASN.1 Structures
51
+
52
+
PHPASN1 offers you a class for each of the implemented ASN.1 universal types.
53
+
The constructors should be pretty self explanatory so you should have no big trouble getting started.
54
+
All data will be encoded using [DER encoding][8]
55
+
56
+
```php
57
+
use FG\ASN1\OID;
58
+
use FG\ASN1\Universal\Integer;
59
+
use FG\ASN1\Universal\Boolean;
60
+
use FG\ASN1\Universal\Enumerated;
61
+
use FG\ASN1\Universal\IA5String;
62
+
use FG\ASN1\Universal\ObjectIdentifier;
63
+
use FG\ASN1\Universal\PrintableString;
64
+
use FG\ASN1\Universal\Sequence;
65
+
use FG\ASN1\Universal\Set;
66
+
use FG\ASN1\Universal\NullObject;
67
+
68
+
$integer = new Integer(123456);
69
+
$boolean = new Boolean(true);
70
+
$enum = new Enumerated(1);
71
+
$ia5String = new IA5String('Hello world');
72
+
73
+
$asnNull = new NullObject();
74
+
$objectIdentifier1 = new ObjectIdentifier('1.2.250.1.16.9');
75
+
$objectIdentifier2 = new ObjectIdentifier(OID::RSA_ENCRYPTION);
76
+
$printableString = new PrintableString('Foo bar');
77
+
78
+
$sequence = new Sequence($integer, $boolean, $enum, $ia5String);
79
+
$set = new Set($sequence, $asnNull, $objectIdentifier1, $objectIdentifier2, $printableString);
80
+
81
+
$myBinary = $sequence->getBinary();
82
+
$myBinary .= $set->getBinary();
83
+
84
+
echo base64_encode($myBinary);
85
+
```
86
+
87
+
88
+
### Decoding binary data
89
+
90
+
Decoding BER encoded binary data is just as easy as encoding it:
91
+
92
+
```php
93
+
use FG\ASN1\ASNObject;
94
+
95
+
$base64String = ...
96
+
$binaryData = base64_decode($base64String);
97
+
$asnObject = ASNObject::fromBinary($binaryData);
98
+
99
+
100
+
// do stuff
101
+
```
102
+
103
+
If you already know exactly how your expected data should look like you can use the `FG\ASN1\TemplateParser`:
104
+
105
+
```php
106
+
use FG\ASN1\TemplateParser;
107
+
108
+
// first define your template
109
+
$template = [
110
+
Identifier::SEQUENCE => [
111
+
Identifier::SET => [
112
+
Identifier::OBJECT_IDENTIFIER,
113
+
Identifier::SEQUENCE => [
114
+
Identifier::INTEGER,
115
+
Identifier::BITSTRING,
116
+
]
117
+
]
118
+
]
119
+
];
120
+
121
+
// if your binary data is not matching the template you provided this will throw an `\Exception`:
122
+
$parser = new TemplateParser();
123
+
$object = $parser->parseBinary($data, $template);
124
+
125
+
// there is also a convenience function if you parse binary data from base64:
126
+
$object = $parser->parseBase64($data, $template);
127
+
```
128
+
129
+
You can use this function to make sure your data has exactly the format you are expecting.
130
+
131
+
### Navigating decoded data
132
+
133
+
All constructed classes (i.e. `Sequence` and `Set`) can be navigated by array access or using an iterator.
134
+
You can find examples
135
+
[here](https://github.com/fgrosse/PHPASN1/blob/f6442cadda9d36f3518c737e32f28300a588b777/tests/ASN1/Universal/SequenceTest.php#L148-148),
136
+
[here](https://github.com/fgrosse/PHPASN1/blob/f6442cadda9d36f3518c737e32f28300a588b777/tests/ASN1/Universal/SequenceTest.php#L121) and
137
+
[here](https://github.com/fgrosse/PHPASN1/blob/f6442cadda9d36f3518c737e32f28300a588b777/tests/ASN1/TemplateParserTest.php#L45).
138
+
139
+
140
+
### Give me more examples!
141
+
142
+
To see some example usage of the API classes or some generated output check out the [examples](https://github.com/fgrosse/PHPASN1/tree/master/examples).
143
+
144
+
145
+
### How do I contribute?
146
+
147
+
This project is no longer maintained and thus does not accept any new contributions.
148
+
149
+
### Thanks
150
+
151
+
To [all contributors][1] so far!
152
+
153
+
## License
154
+
155
+
This library is distributed under the [MIT License](LICENSE).
156
+
157
+
[1]: https://github.com/fgrosse/PHPASN1/graphs/contributors
158
+
[2]: https://getcomposer.org/
159
+
[3]: http://www.itu.int/ITU-T/asn1/
160
+
[4]: http://www.itu.int/ITU-T/recommendations/rec.aspx?rec=x.690
161
+
[5]: http://en.wikipedia.org/wiki/X.509
162
+
[6]: http://en.wikipedia.org/wiki/X.690#BER_encoding
163
+
[7]: http://php.net/manual/en/book.curl.php
164
+
[8]: http://en.wikipedia.org/wiki/X.690#DER_encoding
165
+
[9]: https://styleci.io
166
+
[10]: https://coveralls.io/github/fgrosse/PHPASN1
167
+
[11]: https://github.com/fgrosse/PHPASN1/blob/master/tests/ASN1/TemplateParserTest.php#L16
168
+
[12]: https://groups.google.com/d/forum/phpasn1
169
+
[13]: https://packagist.org/packages/fgrosse/phpasn1#1.5.2
170
+