# ASN.1 String Types
synta supports all ASN.1 string type keywords. Each may carry an optional SIZE
or FROM constraint.
## String type table
| UTF8String | — | `Utf8String` / `Utf8StringRef<'a>` | Full Unicode |
| PrintableString | — | `PrintableString` / `PrintableStringRef<'a>` | Restricted ASCII subset |
| IA5String | — | `IA5String` / `IA5StringRef<'a>` | ASCII (7-bit) |
| TeletexString | T61String | `TeletexString` | Raw bytes; no Ref variant |
| BMPString | — | `BmpString` | Raw bytes; no Ref variant |
| UniversalString | — | `UniversalString` | Raw bytes; no Ref variant |
| GeneralString | — | `GeneralString` | Raw bytes; no Ref variant |
| GraphicString | — | raw bytes | |
| NumericString | — | `NumericString` | Raw bytes; no Ref variant |
| ObjectDescriptor | — | raw bytes | |
| VideotexString | — | raw bytes | |
| VisibleString | ISO646String | `VisibleString` | Raw bytes; no Ref variant |
"Raw bytes" means the type is represented as an opaque octet sequence.
Character-set validation is not applied by synta-codegen for these types.
## UTF-8 strings
```rust
use synta::types::string::Utf8String;
let s = Utf8String::new("Hello, World!".to_string());
let str_ref: &str = s.as_str();
```
Zero-copy variant:
```rust
use synta::types::string::Utf8StringRef;
let s: Utf8StringRef = decoder.decode()?;
let str_ref: &str = s.as_str();
```
## PrintableString
Accepts only: A–Z, a–z, 0–9, space, and `'()+,-./:=?`.
```rust
use synta::types::string::PrintableString;
let ps = PrintableString::new("Hello World".to_string())?;
let str_ref: &str = ps.as_str();
```
## IA5String
Accepts only 7-bit ASCII (characters 0x00–0x7F).
```rust
use synta::types::string::IA5String;
let ia5 = IA5String::new("ASCII only".to_string())?;
let str_ref: &str = ia5.as_str();
```
## TeletexString (T61String)
Stored as raw bytes. X.509 certificates sometimes use TeletexString with
Latin-1 (ISO-8859-1) encoding rather than true Teletex.
```rust
use synta::types::string::TeletexString;
let ts: TeletexString = decoder.decode()?;
let bytes: &[u8] = ts.as_bytes();
```
synta-certificate's `decode_string_value` applies Latin-1 normalisation for
TeletexString values when parsing Distinguished Name attributes.
## BMPString
UTF-16 Big Endian encoded Unicode.
```rust
use synta::types::string::BmpString;
let bmp: BmpString = decoder.decode()?;
let bytes: Vec<u8> = bmp.to_ucs2_be(); // raw UCS-2 BE bytes
```
## Ref types and lifetimes
Types with a `Ref` variant borrow from the decoder input buffer, avoiding
allocation. They carry a lifetime parameter tied to the buffer:
```rust
use synta::types::string::Utf8StringRef;
fn inspect<'a>(decoder: &mut Decoder<'a>) -> synta::Result<()> {
let s: Utf8StringRef<'a> = decoder.decode()?;
println!("{}", s.as_str()); // borrows from the original buffer
Ok(())
}
```
To own the string data (e.g., to return it from a function without the buffer),
convert to the owned form:
```rust
let owned: Utf8String = s.to_owned();
```
## Serde representations
When the `serde` feature is enabled, all text string types serialize as plain
JSON strings. `TeletexString`, `BMPString`, and other raw-byte types serialize
as lowercase hex strings.