/// <inheritdoc/> public override byte[] Write() { var res = new List <byte>(); res.Add(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed)); res.AddRange(DerWriter.WriteLength(this.Content, (Asn1Type)this.Asn1Tag)); res.AddRange(this.Content); return(res.ToArray()); }
/// <inheritdoc/> public override byte[] Write() { var res = new List <byte>(); var val = Encoding.UTF8.GetBytes(this.Content); res.Add(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed)); res.AddRange(DerWriter.WriteLength(val, (Asn1Type)this.Asn1Tag)); res.AddRange(val); return(res.ToArray()); }
/// <inheritdoc/> public override byte[] Write() { var res = new List <byte>(); var val = this.Content.ToByteArray().Reverse().ToArray(); res.Add(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed)); res.AddRange(DerWriter.WriteLength(val, (Asn1Type)this.Asn1Tag)); res.AddRange(val); return(res.ToArray()); }
/// <inheritdoc/> public override byte[] Write() { var res = new List <byte>(); var val = (int)Enum.Parse(this.Content.GetType(), this.Content.ToString(), true); var valBytes = new BigInteger(val).ToByteArray().Reverse().ToArray(); res.Add(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed)); res.AddRange(DerWriter.WriteLength(valBytes, (Asn1Type)this.Asn1Tag)); res.AddRange(valBytes); return(res.ToArray()); }
/// <inheritdoc/> public override byte[] Write() { var res = new List <byte>(); byte[] valBytes = null; // SpecialValues if (this.Content == 0) { // If the real value is the value plus zero, there shall be no contents octets in the encoding. return(new byte[] { 0x09, 0x00 }); } else if (double.IsPositiveInfinity(this.Content)) { valBytes = new byte[] { 0x40 }; } else if (double.IsNegativeInfinity(this.Content)) { valBytes = new byte[] { 0x41 }; } else if (double.IsNaN(this.Content)) { valBytes = new byte[] { 0x42 }; } else if (this.Content == -0.0d) { valBytes = new byte[] { 0x43 }; } else { // ToString to find out how many decimal digits value has // to achieve a format that looks like this ####.E-0 // TrimStart will take care of doubles line 0.12314 // Then remove full stop and we will have number of # to add to format string var tmpVal = this.Content.ToString(CultureInfo.InvariantCulture.NumberFormat).TrimStart('0').Replace(".", string.Empty); var format = FormattableString.Invariant($"{new string('#', tmpVal.Length)}\\..E+0"); // Everything was taken care of with format string to meet ITU X690 specification for REAL type. var val = this.Content.ToString(format, CultureInfo.InvariantCulture.NumberFormat); var valEncoded = Encoding.ASCII.GetBytes(val); valBytes = new byte[valEncoded.Length + 1]; valBytes[0] = 0x03; // base 10 encoding valEncoded.CopyTo(valBytes, 1); } res.Add(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed)); res.AddRange(DerWriter.WriteLength(valBytes, (Asn1Type)this.Asn1Tag)); res.AddRange(valBytes); return(res.ToArray()); }
/// <inheritdoc/> public override byte[] Write() { var utcDateTime = this.Content.ToUniversalTime(); var dateTimeString = utcDateTime.ToString("yyMMddHHmmss", CultureInfo.InvariantCulture); dateTimeString += "Z"; var res = Encoding.UTF8.GetBytes(dateTimeString); var resBytes = new List <byte>(); resBytes.Add(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed)); resBytes.AddRange(DerWriter.WriteLength(res, (Asn1Type)this.Asn1Tag)); resBytes.AddRange(res); return(resBytes.ToArray()); }
/// <inheritdoc/> public override byte[] Write() { var resBytes = new List <byte>(); var oidParts = this.Content.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries) .Select(p => Convert.ToInt32(p, CultureInfo.InvariantCulture)).ToArray(); var res = new List <byte>(oidParts.Length); DerWriterUtils.ParseSubIdentifiers(oidParts, res); resBytes.Add(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed)); resBytes.AddRange(DerWriter.WriteLength(res, (Asn1Type)this.Asn1Tag)); resBytes.AddRange(res); return(resBytes.ToArray()); }
/// <inheritdoc/> public override byte[] Write() { var contentBytes = new List <byte>(); foreach (var item in this.Content) { contentBytes.AddRange(item.Write()); } var resBytes = new List <byte>(); resBytes.Add(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed)); resBytes.AddRange(DerWriter.WriteLength(contentBytes, (Asn1Type)this.Asn1Tag)); resBytes.AddRange(contentBytes); return(resBytes.ToArray()); }
/// <inheritdoc/> public override byte[] Write() { var enc = Encoding.GetEncoding("utf-32BE"); if (enc == null) { throw new PlatformNotSupportedException("UTF-32 encoding is not supported on this platform."); } var val = enc.GetBytes(this.Content); var res = new List <byte>(); res.Add(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed)); res.AddRange(DerWriter.WriteLength(val, (Asn1Type)this.Asn1Tag)); res.AddRange(val); return(res.ToArray()); }
/// <inheritdoc/> public override byte[] Write() { var resBytes = new List <byte>(); var oidParts = this.Content.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries) .Select(p => Convert.ToInt32(p, CultureInfo.InvariantCulture)).ToArray(); var res = new List <byte>(oidParts.Length - 1); byte firstByte = (byte)((40 * oidParts[0]) + oidParts[1]); res.Add(firstByte); // first 2 subidentifiers were already computed DerWriterUtils.ParseSubIdentifiers(oidParts.Skip(2).ToArray(), res); resBytes.Add(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed)); resBytes.AddRange(DerWriter.WriteLength(res, (Asn1Type)this.Asn1Tag)); resBytes.AddRange(res); return(resBytes.ToArray()); }
/// <inheritdoc/> public override byte[] Write() { var contentBytes = new List <byte>(); var comparer = new SetComparer(); var orderedContent = this.Content.OrderBy(p => p, comparer); foreach (var item in orderedContent) { contentBytes.AddRange(item.Write()); } var resBytes = new List <byte>(); resBytes.Add(DerWriter.WriteTag(this.Asn1Class, this.Asn1Tag, this.Constructed)); resBytes.AddRange(DerWriter.WriteLength(contentBytes, (Asn1Type)this.Asn1Tag)); resBytes.AddRange(contentBytes); return(resBytes.ToArray()); }