Matroska-Solution / Matroska / NEbml / Core / DTDBase.cs
Code · 119 lines · 4230 bytes
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/* Copyright (c) 2011-2020 Oleg Zee

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * */

namespace NEbml.Core
{
	/// <summary>
	/// Root class for Ebml type schema
	/// </summary>
	public class DTDBase
	{
		protected static ElementDescriptor Container(long id, string name = "")
		{
			return new ElementDescriptor(id, name, ElementType.MasterElement);
		}

		protected static ElementDescriptor Binary(long id, string name = "")
		{
			return new ElementDescriptor(id, name, ElementType.Binary);
		}

		protected static ElementDescriptor Uint(long id, string name = "")
		{
			return new ElementDescriptor(id, name, ElementType.UnsignedInteger);
		}

		protected static ElementDescriptor Int(long id, string name = "")
		{
			return new ElementDescriptor(id, name, ElementType.SignedInteger);
		}

		protected static ElementDescriptor Ascii(long id, string name = "")
		{
			return new ElementDescriptor(id, name, ElementType.AsciiString);
		}

		protected static ElementDescriptor Utf8(long id, string name = "")
		{
			return new ElementDescriptor(id, name, ElementType.Utf8String);
		}

		protected static ElementDescriptor Float(long id, string name = "")
		{
			return new ElementDescriptor(id, name, ElementType.Float);
		}

		protected static ElementDescriptor Date(long id, string name = "")
		{
			return new ElementDescriptor(id, name, ElementType.Date);
		}

		public class MasterElementDescriptor:ElementDescriptor
		{
			protected MasterElementDescriptor(long identifier, string name = "") : base(identifier, name, ElementType.MasterElement) {}
		}
	}

	/// <summary>
	/// Appendix C. EBML Standard definitions.
	/// </summary>
	public class StandardDtd:DTDBase
	{
		private StandardDtd() {}

		public static readonly EBMLDesc
			EBML = new EBMLDesc(0x1a45dfa3);
		public static readonly SignatureSlotDesc
			SignatureSlot = new SignatureSlotDesc(0x1b538667);
		public static readonly ElementDescriptor
			CRC32 = Container(0xc3).Named(nameof(CRC32)),
			Void = Binary(0xec).Named(nameof(Void));

		public sealed class EBMLDesc : MasterElementDescriptor
		{
			internal EBMLDesc(long id) : base(id, "EBML") { }

			public readonly ElementDescriptor
				EBMLVersion          = Uint(0x4286, nameof(EBMLVersion)),
				EBMLReadVersion      = Uint(0x42f7, nameof(EBMLReadVersion)),
				EBMLMaxIDLength      = Uint(0x42f2, nameof(EBMLMaxIDLength)),
				EBMLMaxSizeLength    = Uint(0x42f3, nameof(EBMLMaxSizeLength)),
				DocType              = Ascii(0x4282, nameof(DocType)),
				DocTypeVersion       = Uint(0x4287, nameof(DocTypeVersion)),
				DocTypeReadVersion   = Uint(0x4285, nameof(DocTypeReadVersion));
		}

		public sealed class SignatureSlotDesc : MasterElementDescriptor
		{
			internal SignatureSlotDesc(long id) : base(id, "SignatureSlot") { }

			public readonly ElementDescriptor
				SignatureAlgo = Uint(0x7e8a, nameof(SignatureAlgo)),
				SignatureHash = Uint(0x7e9a, nameof(SignatureHash)),
				SignaturePublicKey = Binary(0x7ea5, nameof(SignaturePublicKey)),
				Signature = Binary(0x7eb5, nameof(Signature)),
				SignatureElements = Container(0x7e5b, nameof(SignatureElements)),
				SignatureElementList = Container(0x7e7b, nameof(SignatureElementList)),
				SignedElement = Binary(0x6532, nameof(SignedElement));
		}
	}
}