コード例 #1
0
ファイル: ASN1Parser.cs プロジェクト: ForNeVeR/pnet
        // Extract a big integer value.
        public byte[] GetBigInt(ASN1Type type)
        {
            if (Type != type)
            {
                // Not the expected type.
                throw new CryptographicException
                          (_("Crypto_InvalidASN1"));
            }
            int len = Length;
            int ofs = Offset;

            byte[] value;
            if (len > 1 && buffer[offset + ofs] == 0)
            {
                // Strip the leading zero byte.
                value = new byte [len - 1];
                Array.Copy(buffer, offset + ofs + 1, value, 0, len - 1);
            }
            else
            {
                // The first byte is non-zero.
                value = new byte [len];
                Array.Copy(buffer, offset + ofs, value, 0, len);
            }
            offset += len + ofs;
            count  -= len + ofs;
            return(value);
        }
コード例 #2
0
        // Add a container to this builder.
        public ASN1Builder AddContainer(ASN1Type type)
        {
            ASN1Builder container = new ASN1Builder(type);

            list.Add(container);
            return(container);
        }
コード例 #3
0
ファイル: ASN1Parser.cs プロジェクト: ForNeVeR/pnet
        public bool IsString()
        {
            ASN1Type type = Type;

            return(type == ASN1Type.PrintableString ||
                   type == ASN1Type.IA5String);
        }
コード例 #4
0
ファイル: ASN1Parser.cs プロジェクト: ForNeVeR/pnet
 public void Skip(ASN1Type type)
 {
     if (Type != type)
     {
         // Not the expected type.
         throw new CryptographicException
                   (_("Crypto_InvalidASN1"));
     }
     Skip();
 }
コード例 #5
0
ファイル: ASN1Parser.cs プロジェクト: ForNeVeR/pnet
 public String GetString(ASN1Type type)
 {
     if (Type != type)
     {
         // Not the expected type.
         throw new CryptographicException
                   (_("Crypto_InvalidASN1"));
     }
     return(GetStringChecked());
 }
コード例 #6
0
ファイル: ASN1Parser.cs プロジェクト: ForNeVeR/pnet
        public String GetString()
        {
            ASN1Type type = Type;

            if (type != ASN1Type.PrintableString &&
                type != ASN1Type.IA5String)
            {
                // Not one of the standard string types.
                throw new CryptographicException
                          (_("Crypto_InvalidASN1"));
            }
            return(GetStringChecked());
        }
コード例 #7
0
ファイル: ASN1Parser.cs プロジェクト: ForNeVeR/pnet
        // Extract a 64-bit integer value.
        public long GetInt64(ASN1Type type)
        {
            if (Type != type)
            {
                // Not the expected type.
                throw new CryptographicException
                          (_("Crypto_InvalidASN1"));
            }
            int  len  = Length;
            int  ofs  = Offset;
            int  posn = 0;
            long value;
            int  byteval;

            if (len < 1)
            {
                // Need at least 1 octet.
                throw new CryptographicException
                          (_("Crypto_InvalidASN1"));
            }
            byteval = buffer[offset + ofs + posn];
            if ((byteval & 0x80) != 0)
            {
                value = (-1L << 8) | (long)(uint)byteval;
            }
            else
            {
                value = (long)byteval;
            }
            ++posn;
            while (posn < len)
            {
                byteval = buffer[offset + ofs + posn];
                value   = (value << 8) | (long)(uint)byteval;
                ++posn;
            }
            offset += len + ofs;
            count  -= len + ofs;
            return(value);
        }
コード例 #8
0
ファイル: ASN1Parser.cs プロジェクト: ForNeVeR/pnet
        // Get a parser for the contents of a field.
        public ASN1Parser GetContents(ASN1Type type, int adjust)
        {
            if (Type != type)
            {
                // Not the expected type.
                throw new CryptographicException
                          (_("Crypto_InvalidASN1"));
            }
            int len = Length;
            int ofs = Offset;

            if (len < adjust)
            {
                // Contents are no long enough.
                throw new CryptographicException
                          (_("Crypto_InvalidASN1"));
            }
            ASN1Parser parser =
                new ASN1Parser(buffer, offset + ofs + adjust, len - adjust);

            offset += len + ofs;
            count  -= len + ofs;
            return(parser);
        }
コード例 #9
0
ファイル: ASN1Parser.cs プロジェクト: ForNeVeR/pnet
        // Get a byte array that contains the contents of a field.
        public byte[] GetContentsAsArray(ASN1Type type, int adjust)
        {
            if (Type != type)
            {
                // Not the expected type.
                throw new CryptographicException
                          (_("Crypto_InvalidASN1"));
            }
            int len = Length;
            int ofs = Offset;

            if (len < adjust)
            {
                // Contents are no long enough.
                throw new CryptographicException
                          (_("Crypto_InvalidASN1"));
            }
            byte[] result = new byte [len - adjust];
            Array.Copy(buffer, offset + ofs + adjust,
                       result, 0, len - adjust);
            offset += len + ofs;
            count  -= len + ofs;
            return(result);
        }
コード例 #10
0
ファイル: ASN1Parser.cs プロジェクト: ForNeVeR/pnet
 // Extract an object identifier.
 public byte[] GetObjectIdentifier(ASN1Type type)
 {
     return(GetContentsAsArray(type));
 }
コード例 #11
0
 // Add a big integer to this builder.
 public void AddBigInt(ASN1Type type, byte[] value)
 {
     list.Add(new ASN1BigIntBuilder(type, value));
 }
コード例 #12
0
 // Add an octet string to this builder.
 public void AddOctetString(ASN1Type type, byte[] value)
 {
     AddByteArray(type, value);
 }
コード例 #13
0
	// Extract a big integer value.
	public byte[] GetBigInt(ASN1Type type)
			{
				if(Type != type)
				{
					// Not the expected type.
					throw new CryptographicException
						(_("Crypto_InvalidASN1"));
				}
				int len = Length;
				int ofs = Offset;
				byte[] value;
				if(len > 1 && buffer[offset + ofs] == 0)
				{
					// Strip the leading zero byte.
					value = new byte [len - 1];
					Array.Copy(buffer, offset + ofs + 1, value, 0, len - 1);
				}
				else
				{
					// The first byte is non-zero.
					value = new byte [len];
					Array.Copy(buffer, offset + ofs, value, 0, len);
				}
				offset += len + ofs;
				count -= len + ofs;
				return value;
			}
コード例 #14
0
	public byte[] GetContentsAsArray(ASN1Type type)
			{
				return GetContentsAsArray(type, 0);
			}
コード例 #15
0
	public void Skip(ASN1Type type)
			{
				if(Type != type)
				{
					// Not the expected type.
					throw new CryptographicException
						(_("Crypto_InvalidASN1"));
				}
				Skip();
			}
コード例 #16
0
		/// <summary>
		/// This is advanced interface - this is what I would like...
		/// </summary>
		/// <param name="asnseq"></param>
		/// <param name="num"></param>
		/// <param name="tip"></param>
		public static void Make(ASN1Sequence asnseq, int num, ASN1Type tip)
		{
			asnseq.ComponentTypes[num] = ASN1ComponentTypeInfo.Make(tip);
		}
コード例 #17
0
 // Add a bit string to this builder.
 public void AddBitString(ASN1Type type, byte[] value)
 {
     list.Add(new ASN1BitStringBuilder(type, value));
 }
コード例 #18
0
 // Add a byte array field to this builder.
 public void AddByteArray(ASN1Type type, byte[] value)
 {
     list.Add(new ASN1ByteBuilder(type, value));
 }
コード例 #19
0
 // Add a set to this builder.
 public ASN1Builder AddSet(ASN1Type type)
 {
     return(AddContainer(type));
 }
コード例 #20
0
 // Constructor.
 public ASN1BitStringContentsBuilder(ASN1Type type) : base(type)
 {
 }
コード例 #21
0
 // Constructor.
 public ASN1BitStringBuilder(ASN1Type type, byte[] value)
     : base(type, 0)
 {
     this.value = value;
 }
コード例 #22
0
 // Constructor.
 public ASN1Int32Builder(ASN1Type type, int value)
     : base(type, 0)
 {
     this.value = value;
 }
コード例 #23
0
 protected ASN1Builder(ASN1Type type, int dummy)
 {
     this.type = type;
     this.list = null;
 }
コード例 #24
0
ファイル: ASN1Parser.cs プロジェクト: ForNeVeR/pnet
 // Get a UTC time value.
 public String GetUTCTime(ASN1Type type)
 {
     return(GetString(type));
 }
コード例 #25
0
		public static ASN1ComponentTypeInfo Make(ASN1Type tip, bool optional)
		{
			return new ASN1ComponentTypeInfo(tip, optional);
		}
コード例 #26
0
	// Add a UTCTime value to this builder.
	public void AddUTCTime(ASN1Type type, String value)
			{
				AddString(type, value);
			}
コード例 #27
0
		public ASN1ComponentTypeInfo(ASN1Type tip, bool optional) 
		{
			this.Type = tip;
			this.isOptional = optional;
		}
コード例 #28
0
		// Constructor.
		public ASN1Int32Builder(ASN1Type type, int value)
			: base(type, 0)
			{
				this.value = value;
			}
コード例 #29
0
	public ASN1Parser GetContents(ASN1Type type)
			{
				return GetContents(type, 0);
			}
コード例 #30
0
		// Constructor.
		public ASN1Int64Builder(ASN1Type type, long value)
			: base(type, 0)
			{
				this.value = value;
			}
コード例 #31
0
	public String GetString(ASN1Type type)
			{
				if(Type != type)
				{
					// Not the expected type.
					throw new CryptographicException
						(_("Crypto_InvalidASN1"));
				}
				return GetStringChecked();
			}
コード例 #32
0
	public ASN1Builder(ASN1Type type)
			{
				this.type = type;
				this.list = new ArrayList();
			}
コード例 #33
0
 public ASN1Builder(ASN1Type type)
 {
     this.type = type;
     this.list = new ArrayList();
 }
コード例 #34
0
	protected ASN1Builder(ASN1Type type, int dummy)
			{
				this.type = type;
				this.list = null;
			}
コード例 #35
0
 // Add an object identifier to this builder.
 public void AddObjectIdentifier(ASN1Type type, byte[] value)
 {
     AddByteArray(type, value);
 }
コード例 #36
0
	// Add a container to this builder.
	public ASN1Builder AddContainer(ASN1Type type)
			{
				ASN1Builder container = new ASN1Builder(type);
				list.Add(container);
				return container;
			}
コード例 #37
0
 // Add a 64-bit integer to this builder.
 public void AddInt64(ASN1Type type, long value)
 {
     list.Add(new ASN1Int64Builder(type, value));
 }
コード例 #38
0
		// Constructor.
		public ASN1BitStringBuilder(ASN1Type type, byte[] value)
			: base(type, 0)
			{
				this.value = value;
			}
コード例 #39
0
ファイル: ASN1Parser.cs プロジェクト: ForNeVeR/pnet
 // Extract an octet string.
 public byte[] GetOctetString(ASN1Type type)
 {
     return(GetContentsAsArray(type));
 }
コード例 #40
0
		// Constructor.
		public ASN1BitStringContentsBuilder(ASN1Type type) : base(type) {}
コード例 #41
0
		public static ASN1ComponentTypeInfo Make(ASN1Type tip)
		{
			return new ASN1ComponentTypeInfo(tip);
		}
コード例 #42
0
	// Add a set to this builder.
	public ASN1Builder AddSet(ASN1Type type)
			{
				return AddContainer(type);
			}
コード例 #43
0
		public static ASN1ComponentTypeInfo Make(ASN1Type tip, bool optional, ASN1Object defaultValue)
		{
			return new ASN1ComponentTypeInfo(tip, optional, defaultValue);
		}
コード例 #44
0
	// Add a byte array field to this builder.
	public void AddByteArray(ASN1Type type, byte[] value)
			{
				list.Add(new ASN1ByteBuilder(type, value));
			}
コード例 #45
0
		/// <summary>
		/// Basic constructor, type w/out qualifiers.
		/// </summary>
		/// <param name="tip">type of the component</param>
		public ASN1ComponentTypeInfo(ASN1Type tip) 
		{
			this.Type = tip;
			this.isOptional = false;
		}
コード例 #46
0
	// Add a bit string to this builder.
	public void AddBitString(ASN1Type type, byte[] value)
			{
				list.Add(new ASN1BitStringBuilder(type, value));
			}
コード例 #47
0
		public ASN1ComponentTypeInfo(ASN1Type tip, ASN1Object defaultValue)
		{
			this.Type = tip;
			this.isOptional = false;
			this.DefaultValue = defaultValue;
		}
コード例 #48
0
 // Add a UTCTime value to this builder.
 public void AddUTCTime(ASN1Type type, String value)
 {
     AddString(type, value);
 }
コード例 #49
0
	// Get a parser for the contents of a field.
	public ASN1Parser GetContents(ASN1Type type, int adjust)
			{
				if(Type != type)
				{
					// Not the expected type.
					throw new CryptographicException
						(_("Crypto_InvalidASN1"));
				}
				int len = Length;
				int ofs = Offset;
				if(len < adjust)
				{
					// Contents are no long enough.
					throw new CryptographicException
						(_("Crypto_InvalidASN1"));
				}
				ASN1Parser parser =
					new ASN1Parser(buffer, offset + ofs + adjust, len - adjust);
				offset += len + ofs;
				count -= len + ofs;
				return parser;
			}
コード例 #50
0
	// Extract an octet string.
	public byte[] GetOctetString(ASN1Type type)
			{
				return GetContentsAsArray(type);
			}
コード例 #51
0
	// Get a byte array that contains the contents of a field.
	public byte[] GetContentsAsArray(ASN1Type type, int adjust)
			{
				if(Type != type)
				{
					// Not the expected type.
					throw new CryptographicException
						(_("Crypto_InvalidASN1"));
				}
				int len = Length;
				int ofs = Offset;
				if(len < adjust)
				{
					// Contents are no long enough.
					throw new CryptographicException
						(_("Crypto_InvalidASN1"));
				}
				byte[] result = new byte [len - adjust];
				Array.Copy(buffer, offset + ofs + adjust,
						   result, 0, len - adjust);
				offset += len + ofs;
				count -= len + ofs;
				return result;
			}
コード例 #52
0
 // Add a 32-bit integer to this builder.
 public void AddInt32(ASN1Type type, int value)
 {
     list.Add(new ASN1Int32Builder(type, value));
 }
コード例 #53
0
	// Extract a bit string.
	public byte[] GetBitString(ASN1Type type)
			{
				return GetContentsAsArray(type, 1);
			}
コード例 #54
0
ファイル: ASN1Parser.cs プロジェクト: ForNeVeR/pnet
 public ASN1Parser GetContents(ASN1Type type)
 {
     return(GetContents(type, 0));
 }
コード例 #55
0
	// Extract a 64-bit integer value.
	public long GetInt64(ASN1Type type)
			{
				if(Type != type)
				{
					// Not the expected type.
					throw new CryptographicException
						(_("Crypto_InvalidASN1"));
				}
				int len = Length;
				int ofs = Offset;
				int posn = 0;
				long value;
				int byteval;
				if(len < 1)
				{
					// Need at least 1 octet.
					throw new CryptographicException
						(_("Crypto_InvalidASN1"));
				}
				byteval = buffer[offset + ofs + posn];
				if((byteval & 0x80) != 0)
				{
					value = (-1L << 8) | (long)(uint)byteval;
				}
				else
				{
					value = (long)byteval;
				}
				++posn;
				while(posn < len)
				{
					byteval = buffer[offset + ofs + posn];
					value = (value << 8) | (long)(uint)byteval;
					++posn;
				}
				offset += len + ofs;
				count -= len + ofs;
				return value;
			}
コード例 #56
0
ファイル: ASN1Parser.cs プロジェクト: ForNeVeR/pnet
 public byte[] GetContentsAsArray(ASN1Type type)
 {
     return(GetContentsAsArray(type, 0));
 }
コード例 #57
0
	// Extract an object identifier.
	public byte[] GetObjectIdentifier(ASN1Type type)
			{
				return GetContentsAsArray(type);
			}
コード例 #58
0
 // Constructor.
 public ASN1Int64Builder(ASN1Type type, long value)
     : base(type, 0)
 {
     this.value = value;
 }
コード例 #59
0
	// Get a UTC time value.
	public String GetUTCTime(ASN1Type type)
			{
				return GetString(type);
			}
コード例 #60
0
 // Add a string to this builder.
 public void AddString(ASN1Type type, String value)
 {
     list.Add(new ASN1ByteBuilder
                  (type, Encoding.UTF8.GetBytes(value)));
 }