Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CrlRevocationListDecoder.cs
1using System;
3using System.Globalization;
4using System.Text;
5using System.Threading.Tasks;
7using Waher.Content;
9
11{
16 {
20 public const string DefaultContentType = "application/pkix-crl";
21
25 public const string DefaultFileExtension = "crl";
26
30 public string[] ContentTypes => [DefaultContentType];
31
35 public string[] FileExtensions => throw new NotImplementedException();
36
43 public bool TryGetContentType(string FileExtension, out string ContentType)
44 {
45 switch (FileExtension.ToLower(CultureInfo.InvariantCulture))
46 {
48 ContentType = DefaultContentType;
49 return true;
50
51 default:
52 ContentType = string.Empty;
53 return false;
54 }
55 }
56
63 public bool TryGetFileExtension(string ContentType, out string FileExtension)
64 {
65 switch (ContentType.ToLower(CultureInfo.InvariantCulture))
66 {
68 FileExtension = DefaultFileExtension;
69 return true;
70
71 default:
72 FileExtension = string.Empty;
73 return false;
74 }
75 }
76
83 public bool Decodes(string ContentType, out Grade Grade)
84 {
85 if (string.Equals(ContentType, DefaultContentType, StringComparison.OrdinalIgnoreCase))
86 {
87 Grade = Grade.Ok;
88 return true;
89 }
90 else
91 {
92 Grade = Grade.NotAtAll;
93 return false;
94 }
95 }
96
107 public Task<ContentResponse> DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair<string, string>[] Fields, Uri BaseUri, ICodecProgress Progress)
108 {
109 if (!ASN1.TryDecodeDer(Data, out object? Decoded) ||
110 Decoded is not Vector Crl ||
111 !CertificateList.TryParse(Crl, out CertificateList? Parsed))
112 {
113 return Task.FromResult(new ContentResponse(new Exception("Unable to parse and decode CRL data.")));
114 }
115
116 return Task.FromResult(new ContentResponse(DefaultContentType, Parsed, Data));
117 }
118 }
119}
Static class for parsing and decoding security objects encoded using Abstract Syntax Notation 1 (ASN....
Definition: ASN1.cs:22
static bool TryDecodeDer(byte[] Data, out object? Value)
Decodes a DER-encoded object.
Definition: ASN1.cs:77
Certificate List, as defined in RFC 5280, §5.1
static bool TryParse(byte[] RawCertificateList, [NotNullWhen(true)] out CertificateList? Parsed)
Tries to parse an ASN.1-encoded Certificate List, as defined in RFC 5280, §5.1.
Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri, ICodecProgress Progress)
Decodes an object.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
const string DefaultFileExtension
Default file extension for CRL files.
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
const string DefaultContentType
Internet Content-Type for Certificate Revocation Lists.
Contains information about a response to a content request.
Interface for reporting progress about an encoding or decoding.
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Grade
Grade enumeration
Definition: Grade.cs:7