示例#1
0
        private void GetAttributesBytes(byte[] bytes, ref int startIndex, string password, byte[] key2, CreditalsType creditalsType, byte paddingByte)
        {
            int messageStartIndex = startIndex - HeaderLength;

            foreach (var attribute in allAttributes)
            {
                if (attribute != null && attribute.Ignore == false)
                {
                    if (attribute is MessageIntegrity)
                    {
                        switch (creditalsType)
                        {
                        case CreditalsType.ShortTerm:
                            (attribute as MessageIntegrity).Value = ComputeShortTermMessageIntegrity(bytes, startIndex, password);
                            break;

                        case CreditalsType.LongTerm:
                            (attribute as MessageIntegrity).Value = ComputeLongTermMessageIntegrity(bytes, startIndex, password);
                            break;

                        case CreditalsType.MsAvedgea:
                            (attribute as MessageIntegrity).Value = ComputeMsAvedgeaMessageIntegrity(bytes, messageStartIndex, startIndex, key2, Realm.Value, MsUsername.Value);
                            break;
                        }
                    }

                    if (attribute is Fingerprint)
                    {
                        (attribute as Fingerprint).Value = ComputeFingerprint(bytes, startIndex);
                    }

                    if (attribute is XorMappedAddress)
                    {
                        (attribute as XorMappedAddress).GetBytes(bytes, ref startIndex, TransactionId);
                    }
                    else
                    {
                        attribute.GetBytes(bytes, ref startIndex);
                    }

                    if (IsAttributePaddingEnabled())
                    {
                        if (startIndex % 4 > 0)
                        {
                            if (paddingByte != 0)
                            {
                                PadAttribute(paddingByte, bytes, startIndex);
                            }
                            startIndex += 4 - startIndex % 4;
                        }
                    }
                }
            }
        }
示例#2
0
        private byte[] GetBytes(byte[] bytes, int startIndex, string password, byte[] key2, CreditalsType creditalsType, byte paddingByte)
        {
            if (bytes == null)
            {
                ComputeMessageLength();
                bytes = new byte[MessageLength + HeaderLength];
            }

            GetHeaderBytes(bytes, ref startIndex);
            GetAttributesBytes(bytes, ref startIndex, password, key2, creditalsType, paddingByte);

            return bytes;
        }
示例#3
0
        private byte[] GetBytes(byte[] bytes, int startIndex, string password, byte[] key2, CreditalsType creditalsType, byte paddingByte)
        {
            if (bytes == null)
            {
                ComputeMessageLength();
                bytes = new byte[MessageLength + HeaderLength];
            }

            GetHeaderBytes(bytes, ref startIndex);
            GetAttributesBytes(bytes, ref startIndex, password, key2, creditalsType, paddingByte);

            return(bytes);
        }
示例#4
0
        private void GetAttributesBytes(byte[] bytes, ref int startIndex, string password, byte[] key2, CreditalsType creditalsType, byte paddingByte)
        {
            int messageStartIndex = startIndex - HeaderLength;

            foreach (var attribute in allAttributes)
            {
                if (attribute != null && attribute.Ignore == false)
                {
                    if (attribute is MessageIntegrity)
                    {
                        switch (creditalsType)
                        {
                            case CreditalsType.ShortTerm:
                                (attribute as MessageIntegrity).Value = ComputeShortTermMessageIntegrity(bytes, startIndex, password);
                                break;
                            case CreditalsType.LongTerm:
                                (attribute as MessageIntegrity).Value = ComputeLongTermMessageIntegrity(bytes, startIndex, password);
                                break;
                            case CreditalsType.MsAvedgea:
                                (attribute as MessageIntegrity).Value = ComputeMsAvedgeaMessageIntegrity(bytes, messageStartIndex, startIndex, key2, Realm.Value, MsUsername.Value);
                                break;
                        }
                    }

                    if (attribute is Fingerprint)
                        (attribute as Fingerprint).Value = ComputeFingerprint(bytes, startIndex);

                    if (attribute is XorMappedAddress)
                        (attribute as XorMappedAddress).GetBytes(bytes, ref startIndex, TransactionId);
                    else
                        attribute.GetBytes(bytes, ref startIndex);

                    if (IsAttributePaddingEnabled())
                    {
                        if (startIndex % 4 > 0)
                        {
                            if (paddingByte != 0)
                                PadAttribute(paddingByte, bytes, startIndex);
                            startIndex += 4 - startIndex % 4;
                        }
                    }
                }
            }
        }