summaryrefslogtreecommitdiffstats
path: root/vendor/der/src/asn1/internal_macros.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/der/src/asn1/internal_macros.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/der/src/asn1/internal_macros.rs')
-rw-r--r--vendor/der/src/asn1/internal_macros.rs75
1 files changed, 75 insertions, 0 deletions
diff --git a/vendor/der/src/asn1/internal_macros.rs b/vendor/der/src/asn1/internal_macros.rs
new file mode 100644
index 000000000..10ad99d23
--- /dev/null
+++ b/vendor/der/src/asn1/internal_macros.rs
@@ -0,0 +1,75 @@
+macro_rules! impl_any_conversions {
+ ($type: ty) => {
+ impl_any_conversions!($type, );
+ };
+ ($type: ty, $($li: lifetime)?) => {
+ impl<'__der: $($li),*, $($li),*> TryFrom<$crate::AnyRef<'__der>> for $type {
+ type Error = $crate::Error;
+
+ fn try_from(any: $crate::AnyRef<'__der>) -> Result<$type> {
+ any.decode_as()
+ }
+ }
+
+ #[cfg(feature = "alloc")]
+ impl<'__der: $($li),*, $($li),*> TryFrom<&'__der $crate::Any> for $type {
+ type Error = $crate::Error;
+
+ fn try_from(any: &'__der $crate::Any) -> Result<$type> {
+ any.decode_as()
+ }
+ }
+ };
+}
+
+macro_rules! impl_string_type {
+ ($type: ty, $($li: lifetime)?) => {
+ impl_any_conversions!($type, $($li),*);
+
+ mod __impl_string {
+ use super::*;
+
+ use crate::{
+ ord::OrdIsValueOrd, BytesRef, DecodeValue, EncodeValue, Header, Length, Reader,
+ Result, Writer,
+ };
+ use core::{fmt, str};
+
+ impl<$($li),*> AsRef<str> for $type {
+ fn as_ref(&self) -> &str {
+ self.as_str()
+ }
+ }
+
+ impl<$($li),*> AsRef<[u8]> for $type {
+ fn as_ref(&self) -> &[u8] {
+ self.as_bytes()
+ }
+ }
+
+ impl<'__der: $($li),*, $($li),*> DecodeValue<'__der> for $type {
+ fn decode_value<R: Reader<'__der>>(reader: &mut R, header: Header) -> Result<Self> {
+ Self::new(BytesRef::decode_value(reader, header)?.as_slice())
+ }
+ }
+
+ impl<$($li),*> EncodeValue for $type {
+ fn value_len(&self) -> Result<Length> {
+ self.inner.value_len()
+ }
+
+ fn encode_value(&self, writer: &mut impl Writer) -> Result<()> {
+ self.inner.encode_value(writer)
+ }
+ }
+
+ impl<$($li),*> OrdIsValueOrd for $type {}
+
+ impl<$($li),*> fmt::Display for $type {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.write_str(self.as_str())
+ }
+ }
+ }
+ };
+}