public KERB_ERROR_DATA(
     Asn1Integer param0,
     Asn1OctetString param1)
 {
     this.data_type = param0;
     this.data_value = param1;
 }
        /// <summary>
        /// Decodes the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer that contains a PER encoding result.</param>
        /// <param name="aligned">Indicating whether the PER decoding is aligned.</param>
        protected override void ValuePerDecode(IAsn1DecodingBuffer buffer, bool aligned = true)
        {
            Asn1Integer ai = new Asn1Integer(null, Constraints.Min, Constraints.Max);

            ai.PerDecode(buffer, aligned);
            Value = allowedValues[(int)ai.Value];
        }
 public ErectDomainRequest(
     Asn1Integer subHeight,
     Asn1Integer subInterval)
 {
     this.subHeight = subHeight;
     this.subInterval = subInterval;
 }
 public StatsResponseValueV2(
     Asn1Integer threadCountTag,
     Asn1Integer threadCount,
     Asn1Integer callTimeTag,
     Asn1Integer callTime,
     Asn1Integer entriesReturnedTag,
     Asn1Integer entriesReturned,
     Asn1Integer entriesVisitedTag,
     Asn1Integer entriesVisited,
     Asn1Integer filterTag,
     Asn1OctetString filter,
     Asn1Integer indexTag,
     Asn1OctetString index)
 {
     this.threadCountTag = threadCountTag;
     this.threadCount = threadCount;
     this.callTimeTag = callTimeTag;
     this.callTime = callTime;
     this.entriesReturnedTag = entriesReturnedTag;
     this.entriesReturned = entriesReturned;
     this.entriesVisitedTag = entriesVisitedTag;
     this.entriesVisited = entriesVisited;
     this.filterTag = filterTag;
     this.filter = filter;
     this.indexTag = indexTag;
     this.index = index;
 }
Beispiel #5
0
        //BER encoding & decoding are implemented in the base class

        #region PER

        /// <summary>
        /// Encodes the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer to which the encoding result will be written.</param>
        public override void PerEncode(IAsn1PerEncodingBuffer buffer)
        {
            if (HasExternalObjects)
            {
                //TODO: write true to the buffer if external element is used and not within the extension root
                //Ref: X.691: 13.3
                buffer.WriteBit(false);
            }
            int i = 0;

            for (; i < allowedValues.Count; i++)
            {
                if (allowedValues[i] == Value)
                {
                    break;
                }
            }
            if (i == allowedValues.Count)
            {
                throw new Asn1ConstraintsNotSatisfied(ExceptionMessages.ConstraintsNotSatisfied + " Invalid enumeration.");
            }

            Asn1Integer ai = new Asn1Integer(i, Min, Max);

            ai.PerEncode(buffer);
        }
 public ExpectedEntryCountRequestValue(
     Asn1Integer searchEntriesMin,
     Asn1Integer searchEntriesMax)
 {
     this.searchEntriesMin = searchEntriesMin;
     this.searchEntriesMax = searchEntriesMax;
 }
 public KRB_ERROR(
     Asn1Integer param0,
     Asn1Integer param1,
     KerberosTime param2,
     Microseconds param3,
     KerberosTime param4,
     Microseconds param5,
     KerbInt32 param6,
     Realm param7,
     PrincipalName param8,
     Realm param9,
     PrincipalName param10,
     KerberosString param11,
     Asn1OctetString param12)
 {
     this.pvno = param0;
     this.msg_type = param1;
     this.ctime = param2;
     this.cusec = param3;
     this.stime = param4;
     this.susec = param5;
     this.error_code = param6;
     this.crealm = param7;
     this.cname = param8;
     this.realm = param9;
     this.sname = param10;
     this.e_text = param11;
     this.e_data = param12;
 }
 public VerifyNameRequestValue(
     Asn1Integer Flags,
     Asn1OctetString ServerName)
 {
     this.Flags = Flags;
     this.ServerName = ServerName;
 }
 public KDC_PROXY_MESSAGE(
     Asn1OctetString param0,
     KerberosString param1,
     Asn1Integer param2)
 {
     this.kerb_message = param0;
     this.target_domain = param1;
     this.dclocator_hint = param2;
 }
 public AP_REP(
     Asn1Integer param0,
     Asn1Integer param1,
     EncryptedData param2)
 {
     this.pvno = param0;
     this.msg_type = param1;
     this.enc_part = param2;
 }
 public DirSyncRequestValue(
     Asn1Integer Flags,
     Asn1Integer MaxBytes,
     Asn1OctetString Cookie)
 {
     this.Flags = Flags;
     this.MaxBytes = MaxBytes;
     this.Cookie = Cookie;
 }
 public BindRequest(
     Asn1Integer version,
     LDAPDN name,
     BindRequest_authentication authentication)
 {
     this.version = version;
     this.name = name;
     this.authentication = authentication;
 }
 public DirSyncResponseValue(
     Asn1Integer MoreResults,
     Asn1Integer unused,
     Asn1OctetString CookieServer)
 {
     this.MoreResults = MoreResults;
     this.unused = unused;
     this.CookieServer = CookieServer;
 }
 public StatsResponseValueV3(
     Asn1Integer threadCountTag,
     Asn1Integer threadCount,
     Asn1Integer callTimeTag,
     Asn1Integer callTime,
     Asn1Integer entriesReturnedTag,
     Asn1Integer entriesReturned,
     Asn1Integer entriesVisitedTag,
     Asn1Integer entriesVisited,
     Asn1Integer filterTag,
     Asn1OctetString filter,
     Asn1Integer indexTag,
     Asn1OctetString index,
     Asn1Integer pagesReferencedTag,
     Asn1Integer pagesReferenced,
     Asn1Integer pagesReadTag,
     Asn1Integer pagesRead,
     Asn1Integer pagesPrereadTag,
     Asn1Integer pagesPreread,
     Asn1Integer pagesDirtiedTag,
     Asn1Integer pagesDirtied,
     Asn1Integer pagesRedirtiedTag,
     Asn1Integer pagesRedirtied,
     Asn1Integer logRecordCountTag,
     Asn1Integer logRecordCount,
     Asn1Integer logRecordBytesTag,
     Asn1Integer logRecordBytes)
 {
     this.threadCountTag = threadCountTag;
     this.threadCount = threadCount;
     this.callTimeTag = callTimeTag;
     this.callTime = callTime;
     this.entriesReturnedTag = entriesReturnedTag;
     this.entriesReturned = entriesReturned;
     this.entriesVisitedTag = entriesVisitedTag;
     this.entriesVisited = entriesVisited;
     this.filterTag = filterTag;
     this.filter = filter;
     this.indexTag = indexTag;
     this.index = index;
     this.pagesReferencedTag = pagesReferencedTag;
     this.pagesReferenced = pagesReferenced;
     this.pagesReadTag = pagesReadTag;
     this.pagesRead = pagesRead;
     this.pagesPrereadTag = pagesPrereadTag;
     this.pagesPreread = pagesPreread;
     this.pagesDirtiedTag = pagesDirtiedTag;
     this.pagesDirtied = pagesDirtied;
     this.pagesRedirtiedTag = pagesRedirtiedTag;
     this.pagesRedirtied = pagesRedirtied;
     this.logRecordCountTag = logRecordCountTag;
     this.logRecordCount = logRecordCount;
     this.logRecordBytesTag = logRecordBytesTag;
     this.logRecordBytes = logRecordBytes;
 }
 public Ticket(
     Asn1Integer param0,
     Realm param1,
     PrincipalName param2,
     EncryptedData param3)
 {
     this.tkt_vno = param0;
     this.realm = param1;
     this.sname = param2;
     this.enc_part = param3;
 }
 public KRB_SAFE(
     Asn1Integer param0,
     Asn1Integer param1,
     KRB_SAFE_BODY param2,
     Checksum param3)
 {
     this.pvno = param0;
     this.msg_type = param1;
     this.safe_body = param2;
     this.cksum = param3;
 }
 public TGS_REQ(
     Asn1Integer param0,
     Asn1Integer param1,
     Asn1SequenceOf<PA_DATA> param2,
     KDC_REQ_BODY param3)
 {
     this.pvno = param0;
     this.msg_type = param1;
     this.padata = param2;
     this.req_body = param3;
 }
 public DomainParameters()
 {
     this.maxChannelIds = null;
     this.maxUserIds = null;
     this.maxTokenIds = null;
     this.numPriorities = null;
     this.minThroughput = null;
     this.maxHeight = null;
     this.maxMCSPDUsize = null;
     this.protocolVersion = null;
 }
Beispiel #19
0
        /// <summary>
        /// Encodes the content of the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer to which the encoding result will be written.</param>
        protected override void ValuePerEncode(IAsn1PerEncodingBuffer buffer)
        {
            //Encode an index specifying the chosen alternative, Ref: X.691: 22
            Asn1Integer ai = new Asn1Integer(choiceIndexInFieldsMemberInfo, 0, definedAllowedIndices.Count - 1);

            ai.PerEncode(buffer);
            //Encode the chosen alternative
            Asn1Object obj = GetData();

            obj.PerEncode(buffer);
        }
 public ConferenceCreateResponse(
     UserID nodeID,
     Asn1Integer tag,
     ConferenceCreateResponse_result result,
     UserData userData)
 {
     this.nodeID = nodeID;
     this.tag = tag;
     this.result = result;
     this.userData = userData;
 }
 public KRB_CRED(
     Asn1Integer param0,
     Asn1Integer param1,
     Asn1SequenceOf<Ticket> param2,
     EncryptedData param3)
 {
     this.pvno = param0;
     this.msg_type = param1;
     this.tickets = param2;
     this.enc_part = param3;
 }
 public Connect_Response(
     Result result,
     Asn1Integer calledConnectId,
     DomainParameters domainParameters,
     Asn1OctetString userData)
 {
     this.result = result;
     this.calledConnectId = calledConnectId;
     this.domainParameters = domainParameters;
     this.userData = userData;
 }
Beispiel #23
0
        /// <summary>
        /// Decodes the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer that contains a PER encoding result.</param>
        /// <param name="aligned">Indicating whether the PER decoding is aligned.</param>
        public override void PerDecode(IAsn1DecodingBuffer buffer, bool aligned = true)
        {
            if (HasExternalObjects)
            {
                buffer.ReadBit();
                //TODO: if true is read, store the decoding value to external object
            }
            Asn1Integer ai = new Asn1Integer(null, Min, Max);

            ai.PerDecode(buffer, aligned);
            Debug.Assert(ai.Value != null, "ai.Value != null");
            Value = allowedValues[(int)ai.Value];
        }
        /// <summary>
        /// Overrode method from System.Object.
        /// </summary>
        /// <param name="obj">The object to be compared.</param>
        /// <returns>True if obj has same data with this instance. False if not.</returns>
        public override bool Equals(object obj)
        {
            // If parameter is null or cannot be cast to Asn1Integer return false.
            Asn1Integer p = obj as Asn1Integer;

            if (p == null)
            {
                return(false);
            }

            // Return true if the fields match.
            return(Value == p.Value);
        }
 public AP_REQ(
     Asn1Integer param0,
     Asn1Integer param1,
     APOptions param2,
     Ticket param3,
     EncryptedData param4)
 {
     this.pvno = param0;
     this.msg_type = param1;
     this.ap_options = param2;
     this.ticket = param3;
     this.authenticator = param4;
 }
Beispiel #26
0
        /// <summary>
        /// Decodes the content of the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer that contains a PER encoding result.</param>
        /// <param name="aligned">Indicating whether the PER decoding is aligned.</param>
        protected override void ValuePerDecode(IAsn1DecodingBuffer buffer, bool aligned = true)
        {
            //Decode the index specifying the chosen alternative, Ref: X.691: 22
            Asn1Integer ai = new Asn1Integer(null, 0, definedAllowedIndices.Count - 1);

            ai.PerDecode(buffer);
            //Decode the chosen alternative
            Asn1Object[] instances = ChoiceTypeInstances;
            Asn1Object   obj       = instances[(int)ai.Value];

            obj.PerDecode(buffer);
            SetData(definedAllowedIndices[(int)ai.Value], obj);
        }
 public AS_REP(
     Asn1Integer param0,
     Asn1Integer param1,
     Asn1SequenceOf<PA_DATA> param2,
     Realm param3,
     PrincipalName param4,
     Ticket param5,
     EncryptedData param6)
 {
     this.pvno = param0;
     this.msg_type = param1;
     this.padata = param2;
     this.crealm = param3;
     this.cname = param4;
     this.ticket = param5;
     this.enc_part = param6;
 }
 public DomainParameters(
  Asn1Integer maxChannelIds,
  Asn1Integer maxUserIds,
  Asn1Integer maxTokenIds,
  Asn1Integer numPriorities,
  Asn1Integer minThroughput,
  Asn1Integer maxHeight,
  Asn1Integer maxMCSPDUsize,
  Asn1Integer protocolVersion)
 {
     this.maxChannelIds = maxChannelIds;
     this.maxUserIds = maxUserIds;
     this.maxTokenIds = maxTokenIds;
     this.numPriorities = numPriorities;
     this.minThroughput = minThroughput;
     this.maxHeight = maxHeight;
     this.maxMCSPDUsize = maxMCSPDUsize;
     this.protocolVersion = protocolVersion;
 }
 public StatsResponseValueV1(
     Asn1Integer threadCountTag,
     Asn1Integer threadCount,
     Asn1Integer coreTimeTag,
     Asn1Integer coreTime,
     Asn1Integer callTimeTag,
     Asn1Integer callTime,
     Asn1Integer searchSubOperationsTag,
     Asn1Integer searchSubOperations)
 {
     this.threadCountTag = threadCountTag;
     this.threadCount = threadCount;
     this.coreTimeTag = coreTimeTag;
     this.coreTime = coreTime;
     this.callTimeTag = callTimeTag;
     this.callTime = callTime;
     this.searchSubOperationsTag = searchSubOperationsTag;
     this.searchSubOperations = searchSubOperations;
 }
 public SearchRequest(
     LDAPDN baseObject,
     SearchRequest_scope scope,
     SearchRequest_derefAliases derefAliases,
     Asn1Integer sizeLimit,
     Asn1Integer timeLimit,
     Asn1Boolean typesOnly,
     Filter filter,
     AttributeDescriptionList attributes)
 {
     this.baseObject = baseObject;
     this.scope = scope;
     this.derefAliases = derefAliases;
     this.sizeLimit = sizeLimit;
     this.timeLimit = timeLimit;
     this.typesOnly = typesOnly;
     this.filter = filter;
     this.attributes = attributes;
 }
 public SearchRequest(
     LDAPDN baseObject,
     SearchRequest_scope scope,
     SearchRequest_derefAliases derefAliases,
     Asn1Integer sizeLimit,
     Asn1Integer timeLimit,
     Asn1Boolean attrsOnly,
     Filter filter,
     Asn1SequenceOf<AttributeType> attributes)
 {
     this.baseObject = baseObject;
     this.scope = scope;
     this.derefAliases = derefAliases;
     this.sizeLimit = sizeLimit;
     this.timeLimit = timeLimit;
     this.attrsOnly = attrsOnly;
     this.filter = filter;
     this.attributes = attributes;
 }
        //BER encoding & decoding are implemented in the base class

        #region PER

        /// <summary>
        /// Encodes the content of the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer to which the encoding result will be written.</param>
        protected override void ValuePerEncode(IAsn1PerEncodingBuffer buffer)
        {
            int i = 0;

            for (; i < allowedValues.Count; i++)
            {
                if (allowedValues[i] == Value)
                {
                    break;
                }
            }
            if (i == allowedValues.Count)
            {
                throw new Asn1ConstraintsNotSatisfied(ExceptionMessages.ConstraintsNotSatisfied + " Invalid enumeration.");
            }

            Asn1Integer ai = new Asn1Integer(i, Constraints.Min, Constraints.Max);

            ai.PerEncode(buffer);
        }
        public override int BerDecode(IAsn1DecodingBuffer buffer, bool explicitTag = true)
        {
            int headLen = 0;
            Asn1Tag appTag;
            headLen += TagBerDecode(buffer, out appTag);
            int valueLen;
            headLen += LengthBerDecode(buffer, out valueLen);

            int valueLenDecode = 0;
            version = new Asn1Integer();
            valueLenDecode += version.BerDecode(buffer);
            name = new LDAPDN();
            valueLenDecode += name.BerDecode(buffer);
            authentication = new AuthenticationChoice();
            valueLenDecode += authentication.BerDecode(buffer);
            if (valueLen != valueLenDecode)
            {
                throw new Asn1DecodingUnexpectedData(ExceptionMessages.DecodingUnexpectedData + " LDAPResult.");
            }
            return headLen + valueLen;
        }
 public Authenticator(
     Asn1Integer param0,
     Realm param1,
     PrincipalName param2,
     Checksum param3,
     Microseconds param4,
     KerberosTime param5,
     EncryptionKey param6,
     KerbUInt32 param7,
     AuthorizationData param8)
 {
     this.authenticator_vno = param0;
     this.crealm = param1;
     this.cname = param2;
     this.cksum = param3;
     this.cusec = param4;
     this.ctime = param5;
     this.subkey = param6;
     this.seq_number = param7;
     this.authorization_data = param8;
 }
        /// <summary>
        /// Encodes the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer to which the encoding result will be written.</param>
        public override void PerEncode(IAsn1PerEncodingBuffer buffer)
        {
            if (!VerifyConstraints())
            {
                throw new Asn1ConstraintsNotSatisfied(ExceptionMessages.ConstraintsNotSatisfied);
            }
            long offset;
            if (Min == null)
            {
                Debug.Assert(Value != null, "Value != null");
                offset = (long)Value;
            }
            else
            {
                offset = (long)(Value - Min);
            }

            //Ref. X.691: 10.5.2
            if (Min == null || Max == null) //range is equal to null
            {
                if (offset == 0)
                {
                    buffer.WriteByte(0);
                    return;
                }
                //Ref. X.691: 10.3, 10.4
                byte[] result;
                if (Min == null)
                {
                    result = IntegerEncoding(offset);
                }
                else
                {
                    //lowerBound != null && upperBound == null
                    result = NonNegativeBinaryIntegerPerEncode(offset);
                }
                int len = result.Length;
                buffer.WriteByte((byte)len);
                buffer.WriteBytes(result);
                return;
            }
            else
            {
                //lowerBound != null && upperBound != null, range != null, offset should be non-negative
                //Ref. X.691: 10.5
                if (Range == 1)
                {
                    //X.691: 10.5.4
                    return;
                }
                else if (Range <= 255) //10.5.7: a)
                {
                    int bitFieldSize = 1;
                    while (Range > (1 << (bitFieldSize)))
                    {
                        bitFieldSize++;
                    }
                    byte[] temp = new byte[] { (byte)offset };
                    buffer.WriteBits(temp, 8 - bitFieldSize, bitFieldSize);
                    return;
                }
                else if (Range == 256) //10.5.7: b)
                {
                    buffer.WriteByte((byte)offset);
                    return;
                }
                else if (Range <= 256 * 256) //10.5.7: c)
                {
                    byte[] bytes = NonNegativeBinaryIntegerPerEncode(offset);//Length is either be 1 or 2
                    if (bytes.Length == 1)
                    {
                        buffer.WriteByte(0);
                    }
                    buffer.WriteBytes(bytes);
                    return;
                }
                else //10.5.7: d)
                {
                    byte[] bytes = NonNegativeBinaryIntegerPerEncode(offset);
                    Asn1Integer len = new Asn1Integer(bytes.Length, 1, 4);
                    len.PerEncode(buffer);
                    buffer.WriteBytes(bytes);
                    return;
                }
            }
        }
        /// <summary>
        /// Decodes the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer that contains a PER encoding result.</param>
        /// <param name="aligned">Indicating whether the PER decoding is aligned.</param>
        public override void PerDecode(IAsn1DecodingBuffer buffer, bool aligned = true)
        {
            if (aligned == false)
            {
                throw new NotImplementedException(ExceptionMessages.UnalignedNotImplemented);
            }
            long baseNum = Min ?? 0;
            //Ref. X.691: 10.5.2
            if (Min == null || Max == null) //range is equal to null
            {
                byte length = buffer.ReadByte();
                if (length == 0)
                {
                    Value = baseNum;
                    return;
                }

                byte[] result = buffer.ReadBytes(length);
                if (Min == null)
                {
                    //No base
                    Value = IntegerDecoding(result);
                }
                else
                {
                    Value = baseNum + NonNegativeBinaryIntegerPerDeocde(result);
                }
            }
            else
            {
                if (Range == 1)
                {
                    this.Value = Min;
                }
                else if (Range <= 255) //10.5.7: a)
                {
                    int bitFieldSize = 1;
                    while (Range > (1 << (bitFieldSize)))
                    {
                        bitFieldSize++;
                    }
                    bool[] result = buffer.ReadBits(bitFieldSize);
                    byte offset = 0;
                    foreach (var b in result)
                    {
                        offset <<= 1;
                        offset += (byte)(b ? 1 : 0);
                    }
                    Value = baseNum + offset;
                }
                else if (Range == 256) //10.5.7: b)
                {
                    Value = baseNum + buffer.ReadByte();
                }
                else if (Range <= 256 * 256) //10.5.7: c)
                {
                    byte[] bytes = buffer.ReadBytes(2);
                    Value = baseNum + bytes[0] * 256 + bytes[1];
                }
                else //10.5.7: d)
                {
                    Asn1Integer len = new Asn1Integer();
                    len.Min = 1;
                    len.Max = 4;
                    len.PerDecode(buffer);
                    Debug.Assert(len.Value != null, "len.Value != null");
                    byte[] bytes = buffer.ReadBytes((int)len.Value);
                    Value = baseNum + NonNegativeBinaryIntegerPerDeocde(bytes);
                }
            }

            if (!VerifyConstraints())
            {
                throw new Asn1ConstraintsNotSatisfied(ExceptionMessages.ConstraintsNotSatisfied);
            }
        }
Beispiel #37
0
        /// <summary>
        /// Decodes an array of objects from a buffer.
        /// </summary>
        /// <typeparam name="T">Type of the objects.</typeparam>
        /// <param name="buffer">A buffer that stores the encoding result of the objects.</param>
        /// <param name="decoder">A method that provides the functionality of decoding a single object.</param>
        /// <param name="minSize">Minimal size of the array.</param>
        /// <param name="maxSize">Maximal size of the array.</param>
        /// <param name="alignAfterDecodeLength">Indicates whether align when the length is decoded.</param>
        /// <returns>An array of the objects that are decoded from the buffer.</returns>
        public static T[] PerDecodeArray <T>(IAsn1DecodingBuffer buffer, PerDecodeSingleObject <T> decoder,
                                             long?minSize = null, long?maxSize = null, bool alignAfterDecodeLength = false)
        {
            List <T> result    = new List <T>();
            long     decodeNum = 0;

            if (minSize == null && maxSize == null)
            {
                bool end = false;
                while (!end)
                {
                    byte lenHead = buffer.ReadByte();
                    if (lenHead > 196)
                    {
                        throw new Asn1DecodingUnexpectedData(ExceptionMessages.DecodingUnexpectedData + " Length in PER fragment illegal.");
                    }
                    else if (lenHead > 192)
                    {
                        long fraNum = lenHead - 192;
                        decodeNum = fraNum * 16 * 1024;
                        end       = false;
                    }
                    else if (lenHead >= 128)
                    {
                        byte lenNext = buffer.ReadByte();
                        decodeNum = 256L * (lenHead - 128) + lenNext;
                        end       = true;
                    }
                    else //lenHead < 128
                    {
                        decodeNum = lenHead;
                        end       = true;
                    }
                    for (long i = 0; i < decodeNum; i++)
                    {
                        T t = decoder(buffer);
                        result.Add(t);
                    }
                }
                return(result.ToArray());
            }
            else if (minSize != null && maxSize != null)
            {
                if (minSize < 0 || maxSize < minSize)
                {
                    throw new Asn1UserDefinedTypeInconsistent(ExceptionMessages.UserDefinedTypeInconsistent + " Size constraints illegal.");
                }
                long range = (long)(maxSize - minSize + 1);
                if (range > 256L * 256)
                {
                    throw new NotImplementedException("Array with big size constraints are not implemented yet.");
                }
                //range < 256 * 256
                if (maxSize == 0) //Ref. X.691: 16.5
                {
                    return(new T[0]);
                }
                if (maxSize != minSize) //Ref. X.691: 16.8
                {
                    //Decode length
                    Asn1Integer ai = new Asn1Integer(null, minSize, maxSize);
                    ai.PerDecode(buffer);
                    if (alignAfterDecodeLength)
                    {
                        buffer.AlignData();
                    }
                    decodeNum = (long)ai.Value;
                }
                else
                {
                    decodeNum = minSize.Value;
                }
                for (long i = 0; i < decodeNum; i++)
                {
                    T t = decoder(buffer);
                    result.Add(t);
                }
                return(result.ToArray());
            }
            else
            {
                throw new NotImplementedException("Array with semi size constraints are not implemented yet.");
            }
        }
 public SearchOptionsRequestValue(
     Asn1Integer Flags)
 {
     this.Flags = Flags;
 }
Beispiel #39
0
 /// <summary>
 /// Encodes an array of objects by PER.
 /// </summary>
 /// <typeparam name="T">The type of the objects.</typeparam>
 /// <param name="buffer">A buffer that will store the encoding result of the objects.</param>
 /// <param name="objs">The array of the objects.</param>
 /// <param name="encoder">A method that provide the functionality of encoding a single object.</param>
 /// <param name="minSize">Minimal size of the array.</param>
 /// <param name="maxSize">Maximal size of the array.</param>
 /// <param name="alignAfterEncodeLength">Indicates whether align after the length is encoded.</param>
 public static void PerEncodeArray <T>(IAsn1PerEncodingBuffer buffer, T[] objs, PerEncodeSingleObject <T> encoder,
                                       long?minSize = null, long?maxSize = null, bool alignAfterEncodeLength = false)
 {
     if (minSize == null && maxSize == null)
     {
         bool len16KMultiple = false;
         int  len            = objs.Length;
         if (len == 0)
         {
             buffer.WriteByte(0);
             return;
         }
         int curIndex = 0;
         while (curIndex != len)
         {
             int writeContentNum = 0;
             int rest            = len - curIndex;
             if (rest < 128) //X.691: 10.9 a)
             {
                 buffer.WriteByte((byte)rest);
                 writeContentNum = rest;
                 len16KMultiple  = false;
             }
             else if (rest < 16 * 1024) //X.691: 10.9 b) 16K
             {
                 buffer.WriteByte((byte)(128 | (rest >> 8)));
                 buffer.WriteByte((byte)(rest & 255));
                 writeContentNum = rest;
                 len16KMultiple  = false;
             }
             else
             {
                 int fragmentNum = rest / (16 * 1024);//number of 16K items, X.691: 10.9 c)
                 if (fragmentNum > 4)
                 {
                     fragmentNum = 4;
                 }
                 buffer.WriteByte((byte)(192 + fragmentNum));
                 writeContentNum = fragmentNum * 16 * 1024;
                 len16KMultiple  = true;
             }
             for (int i = 0; i < writeContentNum; i++, curIndex++)
             {
                 encoder(buffer, objs[curIndex]);
             }
         }
         if (len16KMultiple)
         {
             //throw new Asn1InvalidArgument("Objsys bug");
             buffer.WriteByte(0);
         }
     }
     else if (minSize != null && maxSize != null)
     {
         if (minSize < 0 || maxSize < minSize)
         {
             throw new Asn1UserDefinedTypeInconsistent(ExceptionMessages.UserDefinedTypeInconsistent + " Size constraints illegal.");
         }
         long range = (long)(maxSize - minSize + 1);
         if (range > 256L * 256)
         {
             throw new NotImplementedException("Array with big size constraints are not implemented yet.");
         }
         //range < 256 * 256
         if (maxSize == 0) //Ref. X.691: 16.5
         {
             return;
         }
         if (maxSize != minSize) //Ref. X.691: 16.8
         {
             //Encode length
             Asn1Integer ai = new Asn1Integer(objs.Length, minSize, maxSize);
             ai.PerEncode(buffer);
             if (alignAfterEncodeLength)
             {
                 buffer.AlignData();
             }
         }
         foreach (T curObj in objs)
         {
             encoder(buffer, curObj);
         }
     }
     else
     {
         throw new NotImplementedException("Array with semi size constraints are not implemented yet.");
     }
 }
        /// <summary>
        /// Encodes the content of the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer to which the encoding result will be written.</param>
        protected override void ValuePerEncode(IAsn1PerEncodingBuffer buffer)
        {
            long offset;

            if (Constraints == null || !Constraints.HasMin)
            {
                offset = (long)Value;
            }
            else
            {
                offset = (long)(Value - Constraints.Min);
            }

            //Ref. X.691: 10.5.2
            if (Range == null)
            {
                if (offset == 0)
                {
                    buffer.WriteByte(0);
                    return;
                }
                //Ref. X.691: 10.3, 10.4
                byte[] result;
                if (Constraints == null || !Constraints.HasMin)
                {
                    result = IntegerEncoding(offset);
                }
                else
                {
                    //lowerBound != null && upperBound == null
                    result = NonNegativeBinaryIntegerPerEncode(offset);
                }
                int len = result.Length;
                buffer.WriteByte((byte)len);
                buffer.WriteBytes(result);
                return;
            }
            else
            {
                //lowerBound != null && upperBound != null, range != null, offset should be non-negative
                //Ref. X.691: 10.5
                if (Range == 1)
                {
                    //X.691: 10.5.4
                    return;
                }
                else if (Range <= 255) //10.5.7: a)
                {
                    int bitFieldSize = 1;
                    while (Range > (1 << (bitFieldSize)))
                    {
                        bitFieldSize++;
                    }
                    byte[] temp = new byte[] { (byte)offset };
                    buffer.WriteBits(temp, 8 - bitFieldSize, bitFieldSize);
                    return;
                }
                else if (Range == 256) //10.5.7: b)
                {
                    buffer.WriteByte((byte)offset);
                    return;
                }
                else if (Range <= 256 * 256)                                  //10.5.7: c)
                {
                    byte[] bytes = NonNegativeBinaryIntegerPerEncode(offset); //Length is either be 1 or 2
                    if (bytes.Length == 1)
                    {
                        buffer.WriteByte(0);
                    }
                    buffer.WriteBytes(bytes);
                    return;
                }
                else //10.5.7: d)
                {
                    byte[]      bytes = NonNegativeBinaryIntegerPerEncode(offset);
                    Asn1Integer len   = new Asn1Integer(bytes.Length, 1, 4);
                    len.PerEncode(buffer);
                    buffer.WriteBytes(bytes);
                    return;
                }
            }
        }
        /// <summary>
        /// Decodes the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer that contains a PER encoding result.</param>
        /// <param name="aligned">Indicating whether the PER decoding is aligned.</param>
        protected override void ValuePerDecode(IAsn1DecodingBuffer buffer, bool aligned = true)
        {
            long baseNum = (Constraints != null && Constraints.HasMin ? Constraints.Min : 0);

            //Ref. X.691: 10.5.2
            if (Range == null) //range is equal to null
            {
                byte length = buffer.ReadByte();
                if (length == 0)
                {
                    Value = baseNum;
                    return;
                }

                byte[] result = buffer.ReadBytes(length);
                if (Constraints == null || !Constraints.HasMin)
                {
                    //No base
                    Value = IntegerDecoding(result);
                }
                else
                {
                    Value = baseNum + NonNegativeBinaryIntegerPerDeocde(result);
                }
            }
            else
            {
                if (Range == 1)
                {
                    Value = Constraints.Min;
                }
                else if (Range <= 255) //10.5.7: a)
                {
                    int bitFieldSize = 1;
                    while (Range > (1 << (bitFieldSize)))
                    {
                        bitFieldSize++;
                    }
                    bool[] result = buffer.ReadBits(bitFieldSize);
                    byte   offset = 0;
                    foreach (var b in result)
                    {
                        offset <<= 1;
                        offset  += (byte)(b ? 1 : 0);
                    }
                    Value = baseNum + offset;
                }
                else if (Range == 256) //10.5.7: b)
                {
                    Value = baseNum + buffer.ReadByte();
                }
                else if (Range <= 256 * 256) //10.5.7: c)
                {
                    byte[] bytes = buffer.ReadBytes(2);
                    Value = baseNum + bytes[0] * 256 + bytes[1];
                }
                else //10.5.7: d)
                {
                    Asn1Integer len = new Asn1Integer {
                        Constraints = new Asn1IntegerBound {
                            Min = 1, Max = 4
                        }
                    };
                    len.PerDecode(buffer);
                    byte[] bytes = buffer.ReadBytes((int)len.Value);
                    Value = baseNum + NonNegativeBinaryIntegerPerDeocde(bytes);
                }
            }
        }
Beispiel #42
0
        /// <summary>
        /// Decodes the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer that contains a PER encoding result.</param>
        /// <param name="aligned">Indicating whether the PER decoding is aligned.</param>
        public override void PerDecode(IAsn1DecodingBuffer buffer, bool aligned = true)
        {
            if (aligned == false)
            {
                throw new NotImplementedException(ExceptionMessages.UnalignedNotImplemented);
            }
            long baseNum = Min ?? 0;

            //Ref. X.691: 10.5.2
            if (Min == null || Max == null) //range is equal to null
            {
                byte length = buffer.ReadByte();
                if (length == 0)
                {
                    Value = baseNum;
                    return;
                }

                byte[] result = buffer.ReadBytes(length);
                if (Min == null)
                {
                    //No base
                    Value = IntegerDecoding(result);
                }
                else
                {
                    Value = baseNum + NonNegativeBinaryIntegerPerDeocde(result);
                }
            }
            else
            {
                if (Range == 1)
                {
                    this.Value = Min;
                }
                else if (Range <= 255) //10.5.7: a)
                {
                    int bitFieldSize = 1;
                    while (Range > (1 << (bitFieldSize)))
                    {
                        bitFieldSize++;
                    }
                    bool[] result = buffer.ReadBits(bitFieldSize);
                    byte   offset = 0;
                    foreach (var b in result)
                    {
                        offset <<= 1;
                        offset  += (byte)(b ? 1 : 0);
                    }
                    Value = baseNum + offset;
                }
                else if (Range == 256) //10.5.7: b)
                {
                    Value = baseNum + buffer.ReadByte();
                }
                else if (Range <= 256 * 256) //10.5.7: c)
                {
                    byte[] bytes = buffer.ReadBytes(2);
                    Value = baseNum + bytes[0] * 256 + bytes[1];
                }
                else //10.5.7: d)
                {
                    Asn1Integer len = new Asn1Integer();
                    len.Min = 1;
                    len.Max = 4;
                    len.PerDecode(buffer);
                    Debug.Assert(len.Value != null, "len.Value != null");
                    byte[] bytes = buffer.ReadBytes((int)len.Value);
                    Value = baseNum + NonNegativeBinaryIntegerPerDeocde(bytes);
                }
            }

            if (!VerifyConstraints())
            {
                throw new Asn1ConstraintsNotSatisfied(ExceptionMessages.ConstraintsNotSatisfied);
            }
        }
Beispiel #43
0
        /// <summary>
        /// Encodes the object by PER.
        /// </summary>
        /// <param name="buffer">A buffer to which the encoding result will be written.</param>
        public override void PerEncode(IAsn1PerEncodingBuffer buffer)
        {
            if (!VerifyConstraints())
            {
                throw new Asn1ConstraintsNotSatisfied(ExceptionMessages.ConstraintsNotSatisfied);
            }
            long offset;

            if (Min == null)
            {
                Debug.Assert(Value != null, "Value != null");
                offset = (long)Value;
            }
            else
            {
                offset = (long)(Value - Min);
            }

            //Ref. X.691: 10.5.2
            if (Min == null || Max == null) //range is equal to null
            {
                if (offset == 0)
                {
                    buffer.WriteByte(0);
                    return;
                }
                //Ref. X.691: 10.3, 10.4
                byte[] result;
                if (Min == null)
                {
                    result = IntegerEncoding(offset);
                }
                else
                {
                    //lowerBound != null && upperBound == null
                    result = NonNegativeBinaryIntegerPerEncode(offset);
                }
                int len = result.Length;
                buffer.WriteByte((byte)len);
                buffer.WriteBytes(result);
                return;
            }
            else
            {
                //lowerBound != null && upperBound != null, range != null, offset should be non-negative
                //Ref. X.691: 10.5
                if (Range == 1)
                {
                    //X.691: 10.5.4
                    return;
                }
                else if (Range <= 255) //10.5.7: a)
                {
                    int bitFieldSize = 1;
                    while (Range > (1 << (bitFieldSize)))
                    {
                        bitFieldSize++;
                    }
                    byte[] temp = new byte[] { (byte)offset };
                    buffer.WriteBits(temp, 8 - bitFieldSize, bitFieldSize);
                    return;
                }
                else if (Range == 256) //10.5.7: b)
                {
                    buffer.WriteByte((byte)offset);
                    return;
                }
                else if (Range <= 256 * 256)                                  //10.5.7: c)
                {
                    byte[] bytes = NonNegativeBinaryIntegerPerEncode(offset); //Length is either be 1 or 2
                    if (bytes.Length == 1)
                    {
                        buffer.WriteByte(0);
                    }
                    buffer.WriteBytes(bytes);
                    return;
                }
                else //10.5.7: d)
                {
                    byte[]      bytes = NonNegativeBinaryIntegerPerEncode(offset);
                    Asn1Integer len   = new Asn1Integer(bytes.Length, 1, 4);
                    len.PerEncode(buffer);
                    buffer.WriteBytes(bytes);
                    return;
                }
            }
        }