rcgen/
string_types.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
use std::{fmt, str::FromStr};

use crate::{Error, InvalidAsn1String};

/// ASN.1 `PrintableString` type.
///
/// Supports a subset of the ASCII printable characters (described below).
///
/// For the full ASCII character set, use
/// [`Ia5String`][`crate::Ia5String`].
///
/// # Examples
///
/// You can create a `PrintableString` from [a literal string][`&str`] with [`PrintableString::try_from`]:
///
/// ```
/// use rcgen::PrintableString;
/// let hello = PrintableString::try_from("hello").unwrap();
/// ```
///
/// # Supported characters
///
/// PrintableString is a subset of the [ASCII printable characters].
/// For instance, `'@'` is a printable character as per ASCII but can't be part of [ASN.1's `PrintableString`].
///
/// The following ASCII characters/ranges are supported:
///
/// - `A..Z`
/// - `a..z`
/// - `0..9`
/// - "` `" (i.e. space)
/// - `\`
/// - `(`
/// - `)`
/// - `+`
/// - `,`
/// - `-`
/// - `.`
/// - `/`
/// - `:`
/// - `=`
/// - `?`
///
/// [ASCII printable characters]: https://en.wikipedia.org/wiki/ASCII#Printable_characters
/// [ASN.1's `PrintableString`]: https://en.wikipedia.org/wiki/PrintableString
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct PrintableString(String);

impl PrintableString {
	/// Extracts a string slice containing the entire `PrintableString`.
	pub fn as_str(&self) -> &str {
		&self.0
	}
}

impl TryFrom<&str> for PrintableString {
	type Error = Error;

	/// Converts a `&str` to a [`PrintableString`].
	///
	/// Any character not in the [`PrintableString`] charset will be rejected.
	/// See [`PrintableString`] documentation for more information.
	///
	/// The result is allocated on the heap.
	fn try_from(input: &str) -> Result<Self, Error> {
		input.to_string().try_into()
	}
}

impl TryFrom<String> for PrintableString {
	type Error = Error;

	/// Converts a [`String`][`std::string::String`] into a [`PrintableString`]
	///
	/// Any character not in the [`PrintableString`] charset will be rejected.
	/// See [`PrintableString`] documentation for more information.
	///
	/// This conversion does not allocate or copy memory.
	fn try_from(value: String) -> Result<Self, Self::Error> {
		for &c in value.as_bytes() {
			match c {
				b'A'..=b'Z'
				| b'a'..=b'z'
				| b'0'..=b'9'
				| b' '
				| b'\''
				| b'('
				| b')'
				| b'+'
				| b','
				| b'-'
				| b'.'
				| b'/'
				| b':'
				| b'='
				| b'?' => (),
				_ => {
					return Err(Error::InvalidAsn1String(
						InvalidAsn1String::PrintableString(value),
					))
				},
			}
		}
		Ok(Self(value))
	}
}

impl FromStr for PrintableString {
	type Err = Error;

	fn from_str(s: &str) -> Result<Self, Self::Err> {
		s.try_into()
	}
}

impl AsRef<str> for PrintableString {
	fn as_ref(&self) -> &str {
		&self.0
	}
}

impl fmt::Display for PrintableString {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		fmt::Display::fmt(self.as_str(), f)
	}
}

impl PartialEq<str> for PrintableString {
	fn eq(&self, other: &str) -> bool {
		self.as_str() == other
	}
}

impl PartialEq<String> for PrintableString {
	fn eq(&self, other: &String) -> bool {
		self.as_str() == other.as_str()
	}
}

impl PartialEq<&str> for PrintableString {
	fn eq(&self, other: &&str) -> bool {
		self.as_str() == *other
	}
}

impl PartialEq<&String> for PrintableString {
	fn eq(&self, other: &&String) -> bool {
		self.as_str() == other.as_str()
	}
}

/// ASN.1 `IA5String` type.
///
/// # Examples
///
/// You can create a `Ia5String` from [a literal string][`&str`] with [`Ia5String::try_from`]:
///
/// ```
/// use rcgen::Ia5String;
/// let hello = Ia5String::try_from("hello").unwrap();
/// ```
///
/// # Supported characters
///
/// Supports the [International Alphabet No. 5 (IA5)] character encoding, i.e.
/// the 128 characters of the ASCII alphabet. (Note: IA5 is now
/// technically known as the International Reference Alphabet or IRA as
/// specified in the ITU-T's T.50 recommendation).
///
/// For UTF-8, use [`String`][`std::string::String`].
///
/// [International Alphabet No. 5 (IA5)]: https://en.wikipedia.org/wiki/T.50_(standard)
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct Ia5String(String);

impl Ia5String {
	/// Extracts a string slice containing the entire `Ia5String`.
	pub fn as_str(&self) -> &str {
		&self.0
	}
}

impl TryFrom<&str> for Ia5String {
	type Error = Error;

	/// Converts a `&str` to a [`Ia5String`].
	///
	/// Any character not in the [`Ia5String`] charset will be rejected.
	/// See [`Ia5String`] documentation for more information.
	///
	/// The result is allocated on the heap.
	fn try_from(input: &str) -> Result<Self, Error> {
		input.to_string().try_into()
	}
}

impl TryFrom<String> for Ia5String {
	type Error = Error;

	/// Converts a [`String`][`std::string::String`] into a [`Ia5String`]
	///
	/// Any character not in the [`Ia5String`] charset will be rejected.
	/// See [`Ia5String`] documentation for more information.
	fn try_from(input: String) -> Result<Self, Error> {
		if !input.is_ascii() {
			return Err(Error::InvalidAsn1String(InvalidAsn1String::Ia5String(
				input,
			)));
		}
		Ok(Self(input))
	}
}

impl FromStr for Ia5String {
	type Err = Error;

	fn from_str(s: &str) -> Result<Self, Self::Err> {
		s.try_into()
	}
}

impl AsRef<str> for Ia5String {
	fn as_ref(&self) -> &str {
		&self.0
	}
}

impl fmt::Display for Ia5String {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		fmt::Display::fmt(self.as_str(), f)
	}
}

impl PartialEq<str> for Ia5String {
	fn eq(&self, other: &str) -> bool {
		self.as_str() == other
	}
}

impl PartialEq<String> for Ia5String {
	fn eq(&self, other: &String) -> bool {
		self.as_str() == other.as_str()
	}
}

impl PartialEq<&str> for Ia5String {
	fn eq(&self, other: &&str) -> bool {
		self.as_str() == *other
	}
}

impl PartialEq<&String> for Ia5String {
	fn eq(&self, other: &&String) -> bool {
		self.as_str() == other.as_str()
	}
}

/// ASN.1 `TeletexString` type.
///
/// # Examples
///
/// You can create a `TeletexString` from [a literal string][`&str`] with [`TeletexString::try_from`]:
///
/// ```
/// use rcgen::TeletexString;
/// let hello = TeletexString::try_from("hello").unwrap();
/// ```
///
/// # Supported characters
///
/// The standard defines a complex character set allowed in this type. However, quoting the ASN.1
/// [mailing list], "a sizable volume of software in the world treats TeletexString (T61String) as a
/// simple 8-bit string with mostly Windows Latin 1 (superset of iso-8859-1) encoding".
///
/// `TeletexString` is included for backward compatibility, [RFC 5280] say it
/// SHOULD NOT be used for certificates for new subjects.
///
/// [mailing list]: https://www.mail-archive.com/asn1@asn1.org/msg00460.html
/// [RFC 5280]: https://datatracker.ietf.org/doc/html/rfc5280#page-25
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct TeletexString(String);

impl TeletexString {
	/// Extracts a string slice containing the entire `TeletexString`.
	pub fn as_str(&self) -> &str {
		&self.0
	}

	/// Returns a byte slice of this `TeletexString`’s contents.
	pub fn as_bytes(&self) -> &[u8] {
		self.0.as_bytes()
	}
}

impl TryFrom<&str> for TeletexString {
	type Error = Error;

	/// Converts a `&str` to a [`TeletexString`].
	///
	/// Any character not in the [`TeletexString`] charset will be rejected.
	/// See [`TeletexString`] documentation for more information.
	///
	/// The result is allocated on the heap.
	fn try_from(input: &str) -> Result<Self, Error> {
		input.to_string().try_into()
	}
}

impl TryFrom<String> for TeletexString {
	type Error = Error;

	/// Converts a [`String`][`std::string::String`] into a [`TeletexString`]
	///
	/// Any character not in the [`TeletexString`] charset will be rejected.
	/// See [`TeletexString`] documentation for more information.
	///
	/// This conversion does not allocate or copy memory.
	fn try_from(input: String) -> Result<Self, Error> {
		// Check all bytes are visible
		if !input.as_bytes().iter().all(|b| (0x20..=0x7f).contains(b)) {
			return Err(Error::InvalidAsn1String(InvalidAsn1String::TeletexString(
				input,
			)));
		}
		Ok(Self(input))
	}
}

impl FromStr for TeletexString {
	type Err = Error;

	fn from_str(s: &str) -> Result<Self, Self::Err> {
		s.try_into()
	}
}

impl AsRef<str> for TeletexString {
	fn as_ref(&self) -> &str {
		&self.0
	}
}

impl fmt::Display for TeletexString {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		fmt::Display::fmt(self.as_str(), f)
	}
}

impl PartialEq<str> for TeletexString {
	fn eq(&self, other: &str) -> bool {
		self.as_str() == other
	}
}

impl PartialEq<String> for TeletexString {
	fn eq(&self, other: &String) -> bool {
		self.as_str() == other.as_str()
	}
}

impl PartialEq<&str> for TeletexString {
	fn eq(&self, other: &&str) -> bool {
		self.as_str() == *other
	}
}

impl PartialEq<&String> for TeletexString {
	fn eq(&self, other: &&String) -> bool {
		self.as_str() == other.as_str()
	}
}

/// ASN.1 `BMPString` type.
///
/// # Examples
///
/// You can create a `BmpString` from [a literal string][`&str`] with [`BmpString::try_from`]:
///
/// ```
/// use rcgen::BmpString;
/// let hello = BmpString::try_from("hello").unwrap();
/// ```
///
/// # Supported characters
///
/// Encodes Basic Multilingual Plane (BMP) subset of Unicode (ISO 10646),
/// a.k.a. UCS-2.
///
/// Bytes are encoded as UTF-16 big-endian.
///
/// `BMPString` is included for backward compatibility, [RFC 5280] say it
/// SHOULD NOT be used for certificates for new subjects.
///
/// [RFC 5280]: https://datatracker.ietf.org/doc/html/rfc5280#page-25
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct BmpString(Vec<u8>);

impl BmpString {
	/// Returns a byte slice of this `BmpString`'s contents.
	///
	/// The inverse of this method is [`from_utf16be`].
	///
	/// [`from_utf16be`]: BmpString::from_utf16be
	///
	/// # Examples
	///
	/// ```
	/// use rcgen::BmpString;
	/// let s = BmpString::try_from("hello").unwrap();
	///
	/// assert_eq!(&[0, 104, 0, 101, 0, 108, 0, 108, 0, 111], s.as_bytes());
	/// ```
	pub fn as_bytes(&self) -> &[u8] {
		&self.0
	}

	/// Decode a UTF-16BE–encoded vector `vec` into a `BmpString`, returning [Err](`std::result::Result::Err`) if `vec` contains any invalid data.
	pub fn from_utf16be(vec: Vec<u8>) -> Result<Self, Error> {
		if vec.len() % 2 != 0 {
			return Err(Error::InvalidAsn1String(InvalidAsn1String::BmpString(
				"Invalid UTF-16 encoding".to_string(),
			)));
		}

		// FIXME: Update this when `array_chunks` is stabilized.
		for maybe_char in char::decode_utf16(
			vec.chunks_exact(2)
				.map(|chunk| u16::from_be_bytes([chunk[0], chunk[1]])),
		) {
			// We check we only use the BMP subset of Unicode (the first 65 536 code points)
			match maybe_char {
				// Character is in the Basic Multilingual Plane
				Ok(c) if (c as u64) < u64::from(u16::MAX) => (),
				// Characters outside Basic Multilingual Plane or unpaired surrogates
				_ => {
					return Err(Error::InvalidAsn1String(InvalidAsn1String::BmpString(
						"Invalid UTF-16 encoding".to_string(),
					)));
				},
			}
		}
		Ok(Self(vec.to_vec()))
	}
}

impl TryFrom<&str> for BmpString {
	type Error = Error;

	/// Converts a `&str` to a [`BmpString`].
	///
	/// Any character not in the [`BmpString`] charset will be rejected.
	/// See [`BmpString`] documentation for more information.
	///
	/// The result is allocated on the heap.
	fn try_from(value: &str) -> Result<Self, Self::Error> {
		let capacity = value.len().checked_mul(2).ok_or_else(|| {
			Error::InvalidAsn1String(InvalidAsn1String::BmpString(value.to_string()))
		})?;

		let mut bytes = Vec::with_capacity(capacity);

		for code_point in value.encode_utf16() {
			bytes.extend(code_point.to_be_bytes());
		}

		BmpString::from_utf16be(bytes)
	}
}

impl TryFrom<String> for BmpString {
	type Error = Error;

	/// Converts a [`String`][`std::string::String`] into a [`BmpString`]
	///
	/// Any character not in the [`BmpString`] charset will be rejected.
	/// See [`BmpString`] documentation for more information.
	///
	/// Parsing a `BmpString` allocates memory since the UTF-8 to UTF-16 conversion requires a memory allocation.
	fn try_from(value: String) -> Result<Self, Self::Error> {
		value.as_str().try_into()
	}
}

impl FromStr for BmpString {
	type Err = Error;

	fn from_str(s: &str) -> Result<Self, Self::Err> {
		s.try_into()
	}
}

/// ASN.1 `UniversalString` type.
///
/// # Examples
///
/// You can create a `UniversalString` from [a literal string][`&str`] with [`UniversalString::try_from`]:
///
/// ```
/// use rcgen::UniversalString;
/// let hello = UniversalString::try_from("hello").unwrap();
/// ```
///
/// # Supported characters
///
/// The characters which can appear in the `UniversalString` type are any of the characters allowed by
/// ISO/IEC 10646 (Unicode).
///
/// Bytes are encoded like UTF-32 big-endian.
///
/// `UniversalString` is included for backward compatibility, [RFC 5280] say it
/// SHOULD NOT be used for certificates for new subjects.
///
/// [RFC 5280]: https://datatracker.ietf.org/doc/html/rfc5280#page-25
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct UniversalString(Vec<u8>);

impl UniversalString {
	/// Returns a byte slice of this `UniversalString`'s contents.
	///
	/// The inverse of this method is [`from_utf32be`].
	///
	/// [`from_utf32be`]: UniversalString::from_utf32be
	///
	/// # Examples
	///
	/// ```
	/// use rcgen::UniversalString;
	/// let s = UniversalString::try_from("hello").unwrap();
	///
	/// assert_eq!(&[0, 0, 0, 104, 0, 0, 0, 101, 0, 0, 0, 108, 0, 0, 0, 108, 0, 0, 0, 111], s.as_bytes());
	/// ```
	pub fn as_bytes(&self) -> &[u8] {
		&self.0
	}

	/// Decode a UTF-32BE–encoded vector `vec` into a `UniversalString`, returning [Err](`std::result::Result::Err`) if `vec` contains any invalid data.
	pub fn from_utf32be(vec: Vec<u8>) -> Result<UniversalString, Error> {
		if vec.len() % 4 != 0 {
			return Err(Error::InvalidAsn1String(
				InvalidAsn1String::UniversalString("Invalid UTF-32 encoding".to_string()),
			));
		}

		// FIXME: Update this when `array_chunks` is stabilized.
		for maybe_char in vec
			.chunks_exact(4)
			.map(|chunk| u32::from_be_bytes([chunk[0], chunk[1], chunk[2], chunk[3]]))
		{
			if core::char::from_u32(maybe_char).is_none() {
				return Err(Error::InvalidAsn1String(
					InvalidAsn1String::UniversalString("Invalid UTF-32 encoding".to_string()),
				));
			}
		}

		Ok(Self(vec))
	}
}

impl TryFrom<&str> for UniversalString {
	type Error = Error;

	/// Converts a `&str` to a [`UniversalString`].
	///
	/// Any character not in the [`UniversalString`] charset will be rejected.
	/// See [`UniversalString`] documentation for more information.
	///
	/// The result is allocated on the heap.
	fn try_from(value: &str) -> Result<Self, Self::Error> {
		let capacity = value.len().checked_mul(4).ok_or_else(|| {
			Error::InvalidAsn1String(InvalidAsn1String::UniversalString(value.to_string()))
		})?;

		let mut bytes = Vec::with_capacity(capacity);

		// A `char` is any ‘Unicode code point’ other than a surrogate code point.
		// The code units for UTF-32 correspond exactly to Unicode code points.
		// (https://www.unicode.org/reports/tr19/tr19-9.html#Introduction)
		// So any `char` is a valid UTF-32, we just cast it to perform the convertion.
		for char in value.chars().map(|char| char as u32) {
			bytes.extend(char.to_be_bytes())
		}

		UniversalString::from_utf32be(bytes)
	}
}

impl TryFrom<String> for UniversalString {
	type Error = Error;

	/// Converts a [`String`][`std::string::String`] into a [`UniversalString`]
	///
	/// Any character not in the [`UniversalString`] charset will be rejected.
	/// See [`UniversalString`] documentation for more information.
	///
	/// Parsing a `UniversalString` allocates memory since the UTF-8 to UTF-32 conversion requires a memory allocation.
	fn try_from(value: String) -> Result<Self, Self::Error> {
		value.as_str().try_into()
	}
}

#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {

	use crate::{BmpString, Ia5String, PrintableString, TeletexString, UniversalString};

	#[test]
	fn printable_string() {
		const EXAMPLE_UTF8: &str = "CertificateTemplate";
		let printable_string = PrintableString::try_from(EXAMPLE_UTF8).unwrap();
		assert_eq!(printable_string, EXAMPLE_UTF8);
		assert!(PrintableString::try_from("@").is_err());
		assert!(PrintableString::try_from("*").is_err());
	}

	#[test]
	fn ia5_string() {
		const EXAMPLE_UTF8: &str = "CertificateTemplate";
		let ia5_string = Ia5String::try_from(EXAMPLE_UTF8).unwrap();
		assert_eq!(ia5_string, EXAMPLE_UTF8);
		assert!(Ia5String::try_from(String::from('\u{7F}')).is_ok());
		assert!(Ia5String::try_from(String::from('\u{8F}')).is_err());
	}

	#[test]
	fn teletext_string() {
		const EXAMPLE_UTF8: &str = "CertificateTemplate";
		let teletext_string = TeletexString::try_from(EXAMPLE_UTF8).unwrap();
		assert_eq!(teletext_string, EXAMPLE_UTF8);
		assert!(Ia5String::try_from(String::from('\u{7F}')).is_ok());
		assert!(Ia5String::try_from(String::from('\u{8F}')).is_err());
	}

	#[test]
	fn bmp_string() {
		const EXPECTED_BYTES: &[u8] = &[
			0x00, 0x43, 0x00, 0x65, 0x00, 0x72, 0x00, 0x74, 0x00, 0x69, 0x00, 0x66, 0x00, 0x69,
			0x00, 0x63, 0x00, 0x61, 0x00, 0x74, 0x00, 0x65, 0x00, 0x54, 0x00, 0x65, 0x00, 0x6d,
			0x00, 0x70, 0x00, 0x6c, 0x00, 0x61, 0x00, 0x74, 0x00, 0x65,
		];
		const EXAMPLE_UTF8: &str = "CertificateTemplate";
		let bmp_string = BmpString::try_from(EXAMPLE_UTF8).unwrap();
		assert_eq!(bmp_string.as_bytes(), EXPECTED_BYTES);
		assert!(BmpString::try_from(String::from('\u{FFFE}')).is_ok());
		assert!(BmpString::try_from(String::from('\u{FFFF}')).is_err());
	}

	#[test]
	fn universal_string() {
		const EXPECTED_BYTES: &[u8] = &[
			0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00,
			0x00, 0x74, 0x00, 0x00, 0x00, 0x69, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x69,
			0x00, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00,
			0x00, 0x65, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x6d,
			0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00,
			0x00, 0x74, 0x00, 0x00, 0x00, 0x65,
		];
		const EXAMPLE_UTF8: &str = "CertificateTemplate";
		let universal_string = UniversalString::try_from(EXAMPLE_UTF8).unwrap();
		assert_eq!(universal_string.as_bytes(), EXPECTED_BYTES);
	}
}