summaryrefslogtreecommitdiffstats
path: root/vendor/der
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/der
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/der')
-rw-r--r--vendor/der/.cargo-checksum.json2
-rw-r--r--vendor/der/CHANGELOG.md22
-rw-r--r--vendor/der/Cargo.toml13
-rw-r--r--vendor/der/src/asn1.rs3
-rw-r--r--vendor/der/src/asn1/bmp_string.rs164
-rw-r--r--vendor/der/src/asn1/ia5_string.rs15
-rw-r--r--vendor/der/src/asn1/octet_string.rs29
-rw-r--r--vendor/der/src/asn1/printable_string.rs15
-rw-r--r--vendor/der/src/asn1/teletex_string.rs15
-rw-r--r--vendor/der/src/bytes_owned.rs6
-rw-r--r--vendor/der/src/referenced.rs22
-rw-r--r--vendor/der/src/str_owned.rs9
12 files changed, 303 insertions, 12 deletions
diff --git a/vendor/der/.cargo-checksum.json b/vendor/der/.cargo-checksum.json
index 5f3ea3acd..853c177a9 100644
--- a/vendor/der/.cargo-checksum.json
+++ b/vendor/der/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"CHANGELOG.md":"278fb96f82b835b553647cfd14641e7aca7f10f46d0eab5323d2f9918f717e47","Cargo.toml":"e8c4a40eb85ef93d1776c960625d6da2bd7c8282d4417cdedd07b21108ef963a","LICENSE-APACHE":"a9040321c3712d8fd0b09cf52b17445de04a23a10165049ae187cd39e5c86be5","LICENSE-MIT":"ad64fcb9589f162720f3cc5010ad76ca6ad3764e11861f9192c489df176bb71d","README.md":"7eca00af3894b1bf13f1b50f69e8152b388b0fa1349a272e6c665f70ad3c4f31","src/arrayvec.rs":"725cb437e439ab9ab9b9a11faa3993d85308692affd96a854fedb17723c2993f","src/asn1.rs":"1e3666816b3ad85d76e7594e8f06ff0a0c099e12e51d7e34e26a7afd1736c26d","src/asn1/any.rs":"62c484808ab8167704c4d3ff635a650272b2689ccf0f100623589248a84abad5","src/asn1/bit_string.rs":"b34af7569a6eace60b9b8b1429b8d474e75e176c7682d79c002121c040b598fc","src/asn1/boolean.rs":"62f7b026f3990cc21dd4010d1bb26a5d06a6ae7c12cfc1c7d27e551781706291","src/asn1/choice.rs":"721a1322b862e060020b1af9020f7bd80958646c6508aa57aa999d774126ad13","src/asn1/context_specific.rs":"a1ec291b657581f26fee59de02877ea5d287468cf3dfc54a6803ab168bbfc91c","src/asn1/generalized_time.rs":"2d337c6927c56975138425b63a764b03df62e43dc2c76b44d9e51fb8c76fb29b","src/asn1/ia5_string.rs":"3b8ff8c6b147041803a9a5e20f2ac65d7e8906668198fbf90e5225e8f0ea03f6","src/asn1/integer.rs":"daabe34a2b234735bc5bd5ce9350fa687b5f8e602f5367202c48bb91fc3cc808","src/asn1/integer/int.rs":"9c6d72ded7e2d819ec463853e937436c7b8e9baaeed5767e6a316dc5b1b79dde","src/asn1/integer/uint.rs":"3f96610aa6a12a23c9b4f46bf2602207bac35682c1c5fa9fedbe942ff253c285","src/asn1/internal_macros.rs":"0891dfaa499ddfb0e1ca5b857ccd91e652acb61ddbc150737c73029a37daecc2","src/asn1/null.rs":"c28cddc9515b37e1045b75580fb8e53deb7e5649c3a4f0f7f94508267b56600a","src/asn1/octet_string.rs":"ba0713042a735ac30319916bdde9dec4cf1c5b2223c369dc78d53d734bc4d92c","src/asn1/oid.rs":"0448b47bb62c4366e11aabf841bb615964d31530bf9ef67a79bdc1c3c8375d17","src/asn1/optional.rs":"782b9563ad34a405c5adb7fb9b165c2ade57091ef6692698f6ac56209809b1f6","src/asn1/printable_string.rs":"d81e4a059b9d383ce5b72365ebc6bac4878b6e6b67b6ce69a482a34ad4acd761","src/asn1/real.rs":"6513c27c6f5862b8eebe036e0dab9b61b3a91e5a8c5bc995189ddd8278610b1f","src/asn1/sequence.rs":"74e9ac1aaef547ff4288f899d216e63ac081a8415302a15472069d3bf42376ff","src/asn1/sequence_of.rs":"bd6ee2398ca5ffa7ee31633b3a79543d73f742a15cf7a1591c9493981430766d","src/asn1/set_of.rs":"208667d136f66c123a92a3f04475c068c1613e6ee0bd115e9f2766a45a0c4223","src/asn1/teletex_string.rs":"ffaac60318ba4bfd711c5c54972bf4065f3bccf0c4f25a07d3464d3dc47a44d9","src/asn1/utc_time.rs":"37c25624a7a5d86a432619702a54959bffceec411fd5312c9ec14f1aa9af12a2","src/asn1/utf8_string.rs":"c335501488efbc5ce54781e99038e84d6f848c09fe88b53490f9fb4771e5e4b9","src/asn1/videotex_string.rs":"8a663e58e8c73e860613ec7b3078269a6b0e5c371f9d937bd1d4e1bb09f4f28f","src/bytes_owned.rs":"05c1c95bdf18025aa73c6ea5bad5d01850ebf14ed080f344d265a54d5cba57fe","src/bytes_ref.rs":"6c7d2dd1de785180c1ab8235e5f59778b55bdb0e656eb7e82dafdc6b705f51ac","src/datetime.rs":"d0f269d07f4d5ba9a5f7b9b0ae4727b348487cda73210bb8fc5d4575d5a19f1b","src/decode.rs":"bc4b4e5afd1cfa4878d75283b294b52062f800d568389790200db8c239feddae","src/document.rs":"a56d2aa413892becec182f2c8a32377551ed0fdd3ccb292c41b64c1f48b69dad","src/encode.rs":"6a29ff6e583eb2bd8b6a77e06d61378c75c451bb8ca670df480a6ac0dfb8192d","src/encode_ref.rs":"8b0d0010780335efd6bedb3659caf33ed7e514c8c7ae22c701eb4bdea98b3dbd","src/error.rs":"d33bba19755d5e36dbcf864332c1c00b0f29484a0e5929355874edf8f4699bbe","src/header.rs":"33ddb6b8c03c81f163a0d06b1055ccd515618658b6b2ae6b1e47ab84fa96d4f4","src/length.rs":"283b0f4eb8fba660b742e7cba0cb420610ecd8e839cf467c2fea8584d60485cf","src/lib.rs":"a4aad3d71f3ff18d692088d37f0c409f68cdeee22218795c2ca2a83b029e4f54","src/ord.rs":"6b9685d805a5e0060e2432234e04e93ce81e27fdc7711eae86ba2d01c00b70f7","src/reader.rs":"e065486cb68fab6831ddee0f4a9b9635a05259cc1f0ec2939de767f6e375743f","src/reader/nested.rs":"6e5ab8c7cd54f867c8faa60545c441cbe5634f78a91be75bcbd31692fed5fcf0","src/reader/pem.rs":"b5c5e6e7c4737c4f06dc126ae246f5b3cdd1dc4165401bd5219552fcd5e49e7f","src/reader/slice.rs":"6da8050380694ba43effdfaa160e098dd152748af897bef41c6020f9853a76ef","src/referenced.rs":"07f20e75e4b003469d687d4412dd3d5411c92cbbacb7d3c74b646d1aebbd65ff","src/str_owned.rs":"be5389656b3978a0b5b32ca5072feb902b5c49f831045fa214f2e84a8c202000","src/str_ref.rs":"4e4f928ec851ab50ad825792ae42549776d12609ed09da8b7bf2531eec6bd773","src/tag.rs":"1b2c19072ff96fafa74e4200910e31e29808139068409e115b7d31c6b99f0e01","src/tag/class.rs":"dcb78907dbaaf588db0e0929eacd5394553c6ea7f69e8948d733c2597f35d016","src/tag/mode.rs":"52854315fcedf0476015e4afd55c8699f4d4b69d497f58737b0f2572bcaa89bf","src/tag/number.rs":"e89da7d085cdd446bb021c5a5abd46aa53fb95b572f2e15e84cc87b4e2bda86a","src/writer.rs":"36ef12ce394c857b2fc28435dfdac8f11c9b572065e4226781f2af0496d9df60","src/writer/pem.rs":"2d87fbb460fe6f0ff8cf38df2660b09abb0d640def86037b10b2211197ef7e65","src/writer/slice.rs":"7e8c63cb58748cd1f3cd4c65162ce14ef9e9ee07ffc992b6aaef6ff0862495d2","tests/datetime.proptest-regressions":"f88a3c34c88b8438da12a92d47520e1bc926ed80ce890fd4eff4fdded80d3541","tests/datetime.rs":"e8fd8156618e5f8c0378b41617376e589405966cf284887cb3f73617f854a07f","tests/derive.rs":"5102bfac06f50f258d0e4c11597f9a60a78937461ebdb6a0cd43a8e749678db8","tests/examples/spki.der":"55dd4c74b0e48534e2f4e173ceceb50df8f27a7ac2aa8991cc7ae914e030bced","tests/examples/spki.pem":"36d717203cbca1812f05f30e0415251c928b659882092e653221a028571c6853","tests/pem.rs":"e1c27fae3d6cf0d357f49e12fb826bda977134076a5fdd60d38715d1bbc9d9fa","tests/set_of.rs":"c0562109025829e794e00f2097eaa8f7ed3d2b2aa1baca08fbc0c552f6980ab1"},"package":"56acb310e15652100da43d130af8d97b509e95af61aab1c5a7939ef24337ee17"} \ No newline at end of file
+{"files":{"CHANGELOG.md":"9e5838091e2f72850fbe916be0af4cd054af8aa9e511ac3b9d08d123a06a1524","Cargo.toml":"b2a0603d600e6aaed53bbafc40214e388ab03055b7461ce9c52a7ed836a78547","LICENSE-APACHE":"a9040321c3712d8fd0b09cf52b17445de04a23a10165049ae187cd39e5c86be5","LICENSE-MIT":"ad64fcb9589f162720f3cc5010ad76ca6ad3764e11861f9192c489df176bb71d","README.md":"7eca00af3894b1bf13f1b50f69e8152b388b0fa1349a272e6c665f70ad3c4f31","src/arrayvec.rs":"725cb437e439ab9ab9b9a11faa3993d85308692affd96a854fedb17723c2993f","src/asn1.rs":"5b4c031224f5f9f81696d6f484824e745b8ddf167a95deac329aef26acfceebf","src/asn1/any.rs":"62c484808ab8167704c4d3ff635a650272b2689ccf0f100623589248a84abad5","src/asn1/bit_string.rs":"b34af7569a6eace60b9b8b1429b8d474e75e176c7682d79c002121c040b598fc","src/asn1/bmp_string.rs":"6adf94af2aed675ba2cb5fbcff7ee6281505c45fb7eb65e087fb87e89445b8b1","src/asn1/boolean.rs":"62f7b026f3990cc21dd4010d1bb26a5d06a6ae7c12cfc1c7d27e551781706291","src/asn1/choice.rs":"721a1322b862e060020b1af9020f7bd80958646c6508aa57aa999d774126ad13","src/asn1/context_specific.rs":"a1ec291b657581f26fee59de02877ea5d287468cf3dfc54a6803ab168bbfc91c","src/asn1/generalized_time.rs":"2d337c6927c56975138425b63a764b03df62e43dc2c76b44d9e51fb8c76fb29b","src/asn1/ia5_string.rs":"a885312bac486523bb70a9d76343df65651336f62b8dda29d6e02b1c6b73e3a7","src/asn1/integer.rs":"daabe34a2b234735bc5bd5ce9350fa687b5f8e602f5367202c48bb91fc3cc808","src/asn1/integer/int.rs":"9c6d72ded7e2d819ec463853e937436c7b8e9baaeed5767e6a316dc5b1b79dde","src/asn1/integer/uint.rs":"3f96610aa6a12a23c9b4f46bf2602207bac35682c1c5fa9fedbe942ff253c285","src/asn1/internal_macros.rs":"0891dfaa499ddfb0e1ca5b857ccd91e652acb61ddbc150737c73029a37daecc2","src/asn1/null.rs":"c28cddc9515b37e1045b75580fb8e53deb7e5649c3a4f0f7f94508267b56600a","src/asn1/octet_string.rs":"932d2a0cbdb4e4e345b6f62d4c95ce3a3eb23a43d9da192b82c996cc56d7665a","src/asn1/oid.rs":"0448b47bb62c4366e11aabf841bb615964d31530bf9ef67a79bdc1c3c8375d17","src/asn1/optional.rs":"782b9563ad34a405c5adb7fb9b165c2ade57091ef6692698f6ac56209809b1f6","src/asn1/printable_string.rs":"95d871fcd0faafe9905f63ac81a28163803b1cda59c137b0c02d865b142c6bd3","src/asn1/real.rs":"6513c27c6f5862b8eebe036e0dab9b61b3a91e5a8c5bc995189ddd8278610b1f","src/asn1/sequence.rs":"74e9ac1aaef547ff4288f899d216e63ac081a8415302a15472069d3bf42376ff","src/asn1/sequence_of.rs":"bd6ee2398ca5ffa7ee31633b3a79543d73f742a15cf7a1591c9493981430766d","src/asn1/set_of.rs":"208667d136f66c123a92a3f04475c068c1613e6ee0bd115e9f2766a45a0c4223","src/asn1/teletex_string.rs":"f5fb132cac430b2435526496a856ac27bcad7f8c738730debf35c1dfda28f06d","src/asn1/utc_time.rs":"37c25624a7a5d86a432619702a54959bffceec411fd5312c9ec14f1aa9af12a2","src/asn1/utf8_string.rs":"c335501488efbc5ce54781e99038e84d6f848c09fe88b53490f9fb4771e5e4b9","src/asn1/videotex_string.rs":"8a663e58e8c73e860613ec7b3078269a6b0e5c371f9d937bd1d4e1bb09f4f28f","src/bytes_owned.rs":"74224637f212ba36edfb989bf82ee3465d684d5b91b04c5252afe6b7356c310a","src/bytes_ref.rs":"6c7d2dd1de785180c1ab8235e5f59778b55bdb0e656eb7e82dafdc6b705f51ac","src/datetime.rs":"d0f269d07f4d5ba9a5f7b9b0ae4727b348487cda73210bb8fc5d4575d5a19f1b","src/decode.rs":"bc4b4e5afd1cfa4878d75283b294b52062f800d568389790200db8c239feddae","src/document.rs":"a56d2aa413892becec182f2c8a32377551ed0fdd3ccb292c41b64c1f48b69dad","src/encode.rs":"6a29ff6e583eb2bd8b6a77e06d61378c75c451bb8ca670df480a6ac0dfb8192d","src/encode_ref.rs":"8b0d0010780335efd6bedb3659caf33ed7e514c8c7ae22c701eb4bdea98b3dbd","src/error.rs":"d33bba19755d5e36dbcf864332c1c00b0f29484a0e5929355874edf8f4699bbe","src/header.rs":"33ddb6b8c03c81f163a0d06b1055ccd515618658b6b2ae6b1e47ab84fa96d4f4","src/length.rs":"283b0f4eb8fba660b742e7cba0cb420610ecd8e839cf467c2fea8584d60485cf","src/lib.rs":"a4aad3d71f3ff18d692088d37f0c409f68cdeee22218795c2ca2a83b029e4f54","src/ord.rs":"6b9685d805a5e0060e2432234e04e93ce81e27fdc7711eae86ba2d01c00b70f7","src/reader.rs":"e065486cb68fab6831ddee0f4a9b9635a05259cc1f0ec2939de767f6e375743f","src/reader/nested.rs":"6e5ab8c7cd54f867c8faa60545c441cbe5634f78a91be75bcbd31692fed5fcf0","src/reader/pem.rs":"b5c5e6e7c4737c4f06dc126ae246f5b3cdd1dc4165401bd5219552fcd5e49e7f","src/reader/slice.rs":"6da8050380694ba43effdfaa160e098dd152748af897bef41c6020f9853a76ef","src/referenced.rs":"e5927bba4665321632c7dc685a948e00e79c1a6ea2a79fb6e00ce8cc7be80223","src/str_owned.rs":"ffb291a7bea958aa931835103641afb4cd310433a1853dcfc65adc5bafd76e95","src/str_ref.rs":"4e4f928ec851ab50ad825792ae42549776d12609ed09da8b7bf2531eec6bd773","src/tag.rs":"1b2c19072ff96fafa74e4200910e31e29808139068409e115b7d31c6b99f0e01","src/tag/class.rs":"dcb78907dbaaf588db0e0929eacd5394553c6ea7f69e8948d733c2597f35d016","src/tag/mode.rs":"52854315fcedf0476015e4afd55c8699f4d4b69d497f58737b0f2572bcaa89bf","src/tag/number.rs":"e89da7d085cdd446bb021c5a5abd46aa53fb95b572f2e15e84cc87b4e2bda86a","src/writer.rs":"36ef12ce394c857b2fc28435dfdac8f11c9b572065e4226781f2af0496d9df60","src/writer/pem.rs":"2d87fbb460fe6f0ff8cf38df2660b09abb0d640def86037b10b2211197ef7e65","src/writer/slice.rs":"7e8c63cb58748cd1f3cd4c65162ce14ef9e9ee07ffc992b6aaef6ff0862495d2","tests/datetime.proptest-regressions":"f88a3c34c88b8438da12a92d47520e1bc926ed80ce890fd4eff4fdded80d3541","tests/datetime.rs":"e8fd8156618e5f8c0378b41617376e589405966cf284887cb3f73617f854a07f","tests/derive.rs":"5102bfac06f50f258d0e4c11597f9a60a78937461ebdb6a0cd43a8e749678db8","tests/examples/spki.der":"55dd4c74b0e48534e2f4e173ceceb50df8f27a7ac2aa8991cc7ae914e030bced","tests/examples/spki.pem":"36d717203cbca1812f05f30e0415251c928b659882092e653221a028571c6853","tests/pem.rs":"e1c27fae3d6cf0d357f49e12fb826bda977134076a5fdd60d38715d1bbc9d9fa","tests/set_of.rs":"c0562109025829e794e00f2097eaa8f7ed3d2b2aa1baca08fbc0c552f6980ab1"},"package":"fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c"} \ No newline at end of file
diff --git a/vendor/der/CHANGELOG.md b/vendor/der/CHANGELOG.md
index a5063a6c5..02851524e 100644
--- a/vendor/der/CHANGELOG.md
+++ b/vendor/der/CHANGELOG.md
@@ -4,6 +4,28 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## 0.7.8 (2023-08-07)
+### Added
+- `bytes` feature ([#1156])
+- impl `RefToOwned`/`OwnedToRef` for `&[u8]`/`Box<[u8]>` ([#1188])
+- `BmpString` ([#1164])
+
+### Changed
+- no-panic cleanup ([#1169])
+- Bump `der_derive` dependency to v0.7.2 ([#1192])
+
+[#1156]: https://github.com/RustCrypto/formats/pull/1156
+[#1164]: https://github.com/RustCrypto/formats/pull/1164
+[#1169]: https://github.com/RustCrypto/formats/pull/1169
+[#1188]: https://github.com/RustCrypto/formats/pull/1188
+[#1192]: https://github.com/RustCrypto/formats/pull/1192
+
+## 0.7.7 (2023-06-29)
+### Added
+- `TryFrom<String>` impl for strings based on `StrOwned` ([#1064])
+
+[#1064]: https://github.com/RustCrypto/formats/pull/1064
+
## 0.7.6 (2023-05-16)
### Added
- `SetOfVec::{extend, from_iter}` methods ([#1065])
diff --git a/vendor/der/Cargo.toml b/vendor/der/Cargo.toml
index 40e2e6035..a1fcaf133 100644
--- a/vendor/der/Cargo.toml
+++ b/vendor/der/Cargo.toml
@@ -13,7 +13,7 @@
edition = "2021"
rust-version = "1.65"
name = "der"
-version = "0.7.6"
+version = "0.7.8"
authors = ["RustCrypto Developers"]
description = """
Pure Rust embedded-friendly implementation of the Distinguished Encoding Rules
@@ -49,12 +49,17 @@ version = "1.3"
features = ["derive"]
optional = true
+[dependencies.bytes]
+version = "1"
+optional = true
+default-features = false
+
[dependencies.const-oid]
version = "0.9.2"
optional = true
[dependencies.der_derive]
-version = "0.7.1"
+version = "0.7.2"
optional = true
[dependencies.flagset]
@@ -89,6 +94,10 @@ arbitrary = [
"const-oid?/arbitrary",
"std",
]
+bytes = [
+ "dep:bytes",
+ "alloc",
+]
derive = ["dep:der_derive"]
oid = ["dep:const-oid"]
pem = [
diff --git a/vendor/der/src/asn1.rs b/vendor/der/src/asn1.rs
index dead9ae02..b04b1b58f 100644
--- a/vendor/der/src/asn1.rs
+++ b/vendor/der/src/asn1.rs
@@ -6,6 +6,8 @@ mod internal_macros;
mod any;
mod bit_string;
+#[cfg(feature = "alloc")]
+mod bmp_string;
mod boolean;
mod choice;
mod context_specific;
@@ -52,6 +54,7 @@ pub use self::{
pub use self::{
any::Any,
bit_string::BitString,
+ bmp_string::BmpString,
ia5_string::Ia5String,
integer::{int::Int, uint::Uint},
octet_string::OctetString,
diff --git a/vendor/der/src/asn1/bmp_string.rs b/vendor/der/src/asn1/bmp_string.rs
new file mode 100644
index 000000000..b4135d518
--- /dev/null
+++ b/vendor/der/src/asn1/bmp_string.rs
@@ -0,0 +1,164 @@
+//! ASN.1 `BMPString` support.
+
+use crate::{
+ BytesOwned, DecodeValue, EncodeValue, Error, FixedTag, Header, Length, Reader, Result, Tag,
+ Writer,
+};
+use alloc::{boxed::Box, vec::Vec};
+use core::{fmt, str::FromStr};
+
+/// ASN.1 `BMPString` type.
+///
+/// Encodes Basic Multilingual Plane (BMP) subset of Unicode (ISO 10646),
+/// a.k.a. UCS-2.
+#[derive(Clone, Eq, PartialEq, PartialOrd, Ord)]
+pub struct BmpString {
+ bytes: BytesOwned,
+}
+
+impl BmpString {
+ /// Create a new [`BmpString`] from its UCS-2 encoding.
+ pub fn from_ucs2(bytes: impl Into<Box<[u8]>>) -> Result<Self> {
+ let bytes = bytes.into();
+
+ if bytes.len() % 2 != 0 {
+ return Err(Tag::BmpString.length_error());
+ }
+
+ let ret = Self {
+ bytes: bytes.try_into()?,
+ };
+
+ for maybe_char in char::decode_utf16(ret.codepoints()) {
+ match maybe_char {
+ // All surrogates paired and character is in the Basic Multilingual Plane
+ Ok(c) if (c as u64) < u64::from(u16::MAX) => (),
+ // Unpaired surrogates or characters outside Basic Multilingual Plane
+ _ => return Err(Tag::BmpString.value_error()),
+ }
+ }
+
+ Ok(ret)
+ }
+
+ /// Create a new [`BmpString`] from a UTF-8 string.
+ pub fn from_utf8(utf8: &str) -> Result<Self> {
+ let capacity = utf8
+ .len()
+ .checked_mul(2)
+ .ok_or_else(|| Tag::BmpString.length_error())?;
+
+ let mut bytes = Vec::with_capacity(capacity);
+
+ for code_point in utf8.encode_utf16() {
+ bytes.extend(code_point.to_be_bytes());
+ }
+
+ Self::from_ucs2(bytes)
+ }
+
+ /// Borrow the encoded UCS-2 as bytes.
+ pub fn as_bytes(&self) -> &[u8] {
+ self.bytes.as_ref()
+ }
+
+ /// Obtain the inner bytes.
+ #[inline]
+ pub fn into_bytes(self) -> Box<[u8]> {
+ self.bytes.into()
+ }
+
+ /// Get an iterator over characters in the string.
+ pub fn chars(&self) -> impl Iterator<Item = char> + '_ {
+ char::decode_utf16(self.codepoints())
+ .map(|maybe_char| maybe_char.expect("unpaired surrogates checked in constructor"))
+ }
+
+ /// Get an iterator over the `u16` codepoints.
+ pub fn codepoints(&self) -> impl Iterator<Item = u16> + '_ {
+ // TODO(tarcieri): use `array_chunks`
+ self.as_bytes()
+ .chunks_exact(2)
+ .map(|chunk| u16::from_be_bytes([chunk[0], chunk[1]]))
+ }
+}
+
+impl AsRef<[u8]> for BmpString {
+ fn as_ref(&self) -> &[u8] {
+ self.as_bytes()
+ }
+}
+
+impl<'a> DecodeValue<'a> for BmpString {
+ fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self> {
+ Self::from_ucs2(reader.read_vec(header.length)?)
+ }
+}
+
+impl EncodeValue for BmpString {
+ fn value_len(&self) -> Result<Length> {
+ Ok(self.bytes.len())
+ }
+
+ fn encode_value(&self, writer: &mut impl Writer) -> Result<()> {
+ writer.write(self.as_bytes())
+ }
+}
+
+impl FixedTag for BmpString {
+ const TAG: Tag = Tag::BmpString;
+}
+
+impl FromStr for BmpString {
+ type Err = Error;
+
+ fn from_str(s: &str) -> Result<Self> {
+ Self::from_utf8(s)
+ }
+}
+
+impl fmt::Debug for BmpString {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "BmpString(\"{}\")", self)
+ }
+}
+
+impl fmt::Display for BmpString {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ for c in self.chars() {
+ write!(f, "{}", c)?;
+ }
+ Ok(())
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::BmpString;
+ use crate::{Decode, Encode};
+ use alloc::string::ToString;
+ use hex_literal::hex;
+
+ const EXAMPLE_BYTES: &[u8] = &hex!(
+ "1e 26 00 43 00 65 00 72 00 74"
+ " 00 69 00 66 00 69 00 63"
+ " 00 61 00 74 00 65 00 54"
+ " 00 65 00 6d 00 70 00 6c"
+ " 00 61 00 74 00 65"
+ );
+
+ const EXAMPLE_UTF8: &str = "CertificateTemplate";
+
+ #[test]
+ fn decode() {
+ let bmp_string = BmpString::from_der(EXAMPLE_BYTES).unwrap();
+ assert_eq!(bmp_string.to_string(), EXAMPLE_UTF8);
+ }
+
+ #[test]
+ fn encode() {
+ let bmp_string = BmpString::from_utf8(EXAMPLE_UTF8).unwrap();
+ let encoded = bmp_string.to_der().unwrap();
+ assert_eq!(encoded, EXAMPLE_BYTES);
+ }
+}
diff --git a/vendor/der/src/asn1/ia5_string.rs b/vendor/der/src/asn1/ia5_string.rs
index c3f24f01c..1b06dcef9 100644
--- a/vendor/der/src/asn1/ia5_string.rs
+++ b/vendor/der/src/asn1/ia5_string.rs
@@ -90,8 +90,9 @@ mod allocation {
use crate::{
asn1::AnyRef,
referenced::{OwnedToRef, RefToOwned},
- FixedTag, Result, StrOwned, Tag,
+ Error, FixedTag, Result, StrOwned, Tag,
};
+ use alloc::string::String;
use core::{fmt, ops::Deref};
/// ASN.1 `IA5String` type.
@@ -165,6 +166,18 @@ mod allocation {
}
}
}
+
+ impl TryFrom<String> for Ia5String {
+ type Error = Error;
+
+ fn try_from(input: String) -> Result<Self> {
+ Ia5StringRef::new(&input)?;
+
+ StrOwned::new(input)
+ .map(|inner| Self { inner })
+ .map_err(|_| Self::TAG.value_error())
+ }
+ }
}
#[cfg(test)]
diff --git a/vendor/der/src/asn1/octet_string.rs b/vendor/der/src/asn1/octet_string.rs
index d5eb0dd0f..53d8ecb6a 100644
--- a/vendor/der/src/asn1/octet_string.rs
+++ b/vendor/der/src/asn1/octet_string.rs
@@ -112,7 +112,7 @@ mod allocating {
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub struct OctetString {
/// Bitstring represented as a slice of bytes.
- inner: Vec<u8>,
+ pub(super) inner: Vec<u8>,
}
impl OctetString {
@@ -214,6 +214,33 @@ mod allocating {
}
}
+#[cfg(feature = "bytes")]
+mod bytes {
+ use super::OctetString;
+ use crate::{DecodeValue, EncodeValue, FixedTag, Header, Length, Reader, Result, Tag, Writer};
+ use bytes::Bytes;
+
+ impl<'a> DecodeValue<'a> for Bytes {
+ fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self> {
+ OctetString::decode_value(reader, header).map(|octet_string| octet_string.inner.into())
+ }
+ }
+
+ impl EncodeValue for Bytes {
+ fn value_len(&self) -> Result<Length> {
+ self.len().try_into()
+ }
+
+ fn encode_value(&self, writer: &mut impl Writer) -> Result<()> {
+ writer.write(self.as_ref())
+ }
+ }
+
+ impl FixedTag for Bytes {
+ const TAG: Tag = Tag::OctetString;
+ }
+}
+
#[cfg(test)]
mod tests {
use crate::asn1::{OctetStringRef, PrintableStringRef};
diff --git a/vendor/der/src/asn1/printable_string.rs b/vendor/der/src/asn1/printable_string.rs
index 651c5ba23..d2e51d7da 100644
--- a/vendor/der/src/asn1/printable_string.rs
+++ b/vendor/der/src/asn1/printable_string.rs
@@ -124,8 +124,9 @@ mod allocation {
use crate::{
asn1::AnyRef,
referenced::{OwnedToRef, RefToOwned},
- BytesRef, FixedTag, Result, StrOwned, Tag,
+ BytesRef, Error, FixedTag, Result, StrOwned, Tag,
};
+ use alloc::string::String;
use core::{fmt, ops::Deref};
/// ASN.1 `PrintableString` type.
@@ -220,6 +221,18 @@ mod allocation {
}
}
}
+
+ impl TryFrom<String> for PrintableString {
+ type Error = Error;
+
+ fn try_from(input: String) -> Result<Self> {
+ PrintableStringRef::new(&input)?;
+
+ StrOwned::new(input)
+ .map(|inner| Self { inner })
+ .map_err(|_| Self::TAG.value_error())
+ }
+ }
}
#[cfg(test)]
diff --git a/vendor/der/src/asn1/teletex_string.rs b/vendor/der/src/asn1/teletex_string.rs
index cedf727db..337c071e5 100644
--- a/vendor/der/src/asn1/teletex_string.rs
+++ b/vendor/der/src/asn1/teletex_string.rs
@@ -95,8 +95,9 @@ mod allocation {
use crate::{
asn1::AnyRef,
referenced::{OwnedToRef, RefToOwned},
- BytesRef, FixedTag, Result, StrOwned, Tag,
+ BytesRef, Error, FixedTag, Result, StrOwned, Tag,
};
+ use alloc::string::String;
use core::{fmt, ops::Deref};
/// ASN.1 `TeletexString` type.
@@ -179,6 +180,18 @@ mod allocation {
}
}
}
+
+ impl TryFrom<String> for TeletexString {
+ type Error = Error;
+
+ fn try_from(input: String) -> Result<Self> {
+ TeletexStringRef::new(&input)?;
+
+ StrOwned::new(input)
+ .map(|inner| Self { inner })
+ .map_err(|_| Self::TAG.value_error())
+ }
+ }
}
#[cfg(test)]
diff --git a/vendor/der/src/bytes_owned.rs b/vendor/der/src/bytes_owned.rs
index a9f67b21a..b5e928e3b 100644
--- a/vendor/der/src/bytes_owned.rs
+++ b/vendor/der/src/bytes_owned.rs
@@ -83,6 +83,12 @@ impl DerOrd for BytesOwned {
}
}
+impl From<BytesOwned> for Box<[u8]> {
+ fn from(bytes: BytesOwned) -> Box<[u8]> {
+ bytes.inner
+ }
+}
+
impl From<StrRef<'_>> for BytesOwned {
fn from(s: StrRef<'_>) -> BytesOwned {
let bytes = s.as_bytes();
diff --git a/vendor/der/src/referenced.rs b/vendor/der/src/referenced.rs
index bb920db3a..b0c8f0325 100644
--- a/vendor/der/src/referenced.rs
+++ b/vendor/der/src/referenced.rs
@@ -45,3 +45,25 @@ where
self.as_ref().map(|o| o.ref_to_owned())
}
}
+
+#[cfg(feature = "alloc")]
+mod allocating {
+ use super::{OwnedToRef, RefToOwned};
+ use alloc::boxed::Box;
+
+ impl<'a> RefToOwned<'a> for &'a [u8] {
+ type Owned = Box<[u8]>;
+
+ fn ref_to_owned(&self) -> Self::Owned {
+ Box::from(*self)
+ }
+ }
+
+ impl OwnedToRef for Box<[u8]> {
+ type Borrowed<'a> = &'a [u8];
+
+ fn owned_to_ref(&self) -> Self::Borrowed<'_> {
+ self.as_ref()
+ }
+ }
+}
diff --git a/vendor/der/src/str_owned.rs b/vendor/der/src/str_owned.rs
index 25c258e4f..20bfea5bd 100644
--- a/vendor/der/src/str_owned.rs
+++ b/vendor/der/src/str_owned.rs
@@ -21,11 +21,10 @@ pub struct StrOwned {
impl StrOwned {
/// Create a new [`StrOwned`], ensuring that the byte representation of
/// the provided `str` value is shorter than `Length::max()`.
- pub fn new(s: &str) -> Result<Self> {
- Ok(Self {
- inner: String::from(s),
- length: Length::try_from(s.as_bytes().len())?,
- })
+ pub fn new(s: String) -> Result<Self> {
+ let length = Length::try_from(s.as_bytes().len())?;
+
+ Ok(Self { inner: s, length })
}
/// Parse a [`String`] from UTF-8 encoded bytes.