Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ParseUtcTime()

static DateTimeOffset System.Formats.Asn1.AsnDecoder.ParseUtcTime ( ReadOnlySpan< byte > contentOctets,
AsnEncodingRules ruleSet,
int twoDigitYearMax )
inlinestaticprivate

Definition at line 1814 of file AsnDecoder.cs.

1815 {
1816 if ((ruleSet == AsnEncodingRules.DER || ruleSet == AsnEncodingRules.CER) && contentOctets.Length != 13)
1817 {
1818 throw new AsnContentException(System.SR.ContentException_InvalidUnderCerOrDer_TryBer);
1819 }
1820 if (contentOctets.Length < 11 || contentOctets.Length > 17 || (contentOctets.Length & 1) != 1)
1821 {
1822 throw new AsnContentException();
1823 }
1825 int num = ParseNonNegativeIntAndSlice(ref data, 2);
1826 int month = ParseNonNegativeIntAndSlice(ref data, 2);
1827 int day = ParseNonNegativeIntAndSlice(ref data, 2);
1828 int hour = ParseNonNegativeIntAndSlice(ref data, 2);
1829 int minute = ParseNonNegativeIntAndSlice(ref data, 2);
1830 int second = 0;
1831 int hours = 0;
1832 int num2 = 0;
1833 bool flag = false;
1834 if (contentOctets.Length == 17 || contentOctets.Length == 13)
1835 {
1837 }
1838 if (contentOctets.Length == 11 || contentOctets.Length == 13)
1839 {
1840 if (data[0] != 90)
1841 {
1842 throw new AsnContentException();
1843 }
1844 }
1845 else
1846 {
1847 if (data[0] == 45)
1848 {
1849 flag = true;
1850 }
1851 else if (data[0] != 43)
1852 {
1853 throw new AsnContentException();
1854 }
1855 data = data.Slice(1);
1858 }
1859 if (num2 > 59)
1860 {
1861 throw new AsnContentException();
1862 }
1863 TimeSpan timeSpan = new TimeSpan(hours, num2, 0);
1864 if (flag)
1865 {
1866 timeSpan = -timeSpan;
1867 }
1868 int num3 = twoDigitYearMax / 100;
1869 if (num > twoDigitYearMax % 100)
1870 {
1871 num3--;
1872 }
1873 int year = num3 * 100 + num;
1874 try
1875 {
1876 return new DateTimeOffset(year, month, day, hour, minute, second, timeSpan);
1877 }
1878 catch (Exception inner)
1879 {
1880 throw new AsnContentException(System.SR.ContentException_DefaultMessage, inner);
1881 }
1882 }
static int ParseNonNegativeIntAndSlice(ref ReadOnlySpan< byte > data, int bytesToRead)
static string ContentException_InvalidUnderCerOrDer_TryBer
Definition SR.cs:56
static string ContentException_DefaultMessage
Definition SR.cs:50
Definition SR.cs:7

References System.SR.ContentException_DefaultMessage, System.SR.ContentException_InvalidUnderCerOrDer_TryBer, System.Formats.Asn1.AsnDecoder.ParseNonNegativeIntAndSlice(), and System.year.

Referenced by System.Formats.Asn1.AsnDecoder.ReadUtcTime().