public override void Serialize(ref SerializationWriter mySerializationWriter) { mySerializationWriter.CheckNull("mySerializationWriter"); if (_IPAddress != null) { mySerializationWriter.WriteBytesDirect(_IPAddress.GetAddressBytes()); } }
/// <summary> /// This will serialize the whole AFSObject including the common header of an /// AAFSObject and the actual AFSObject /// </summary> /// <param name="myIntegrityCheckAlgorithm"></param> /// <param name="myEncryptionAlgorithm"></param> /// <param name="myCacheSerializeData"></param> /// <returns></returns> public Byte[] Serialize(IIntegrityCheck myIntegrityCheckAlgorithm, ISymmetricEncryption myEncryptionAlgorithm, Boolean myCacheSerializeData) { #region Data Int32 IntegrityCheckValue_Length = 0; Byte[] IntegrityCheckValue = null; Int64 IntegrityCheckValue_Position = 0; Int32 EncryptionParameters_Length = 0; Byte DataPadding_Length = 0; Int32 AdditionalPadding_Length = 0; Byte[] _TmpSerializedAGraphStructure = null; #endregion try { #region Init SerializationWriter SerializationWriter writer = new SerializationWriter(); #endregion #region Pad the length of the EncryptionParameters EncryptionParameters = Encoding.Default.GetBytes("-HIGHSECUREDATA-"); EncryptionParameters_Length = sones.Lib.BufferHelper.AlignBufferLength(EncryptionParameters.Length, 8); #endregion #region Serialize AAFSObjectHeader Byte[] AAFSObjectHeader = new Byte[HeaderLength]; AAFSObjectHeader[0] = HeaderVersion; if (myIntegrityCheckAlgorithm != null) IntegrityCheckValue_Length = myIntegrityCheckAlgorithm.HashSize; if (IntegrityCheckValue_Length % 8 == 0) AAFSObjectHeader[1] = (Byte)(IntegrityCheckValue_Length / 8); else AAFSObjectHeader[1] = (Byte)((IntegrityCheckValue_Length / 8) + 1); if (EncryptionParameters_Length % 8 == 0) AAFSObjectHeader[2] = (Byte)(EncryptionParameters_Length / 8); else AAFSObjectHeader[2] = (Byte)((EncryptionParameters_Length / 8) + 1); AAFSObjectHeader[3] = (Byte)(DataPadding_Length); AAFSObjectHeader[4] = (Byte)(AdditionalPadding_Length / 256); AAFSObjectHeader[5] = (Byte)(AdditionalPadding_Length % 256); AAFSObjectHeader[6] = 0x00; AAFSObjectHeader[7] = 0x00; writer.WriteBytesDirect(AAFSObjectHeader); // 8 Bytes IntegrityCheckValue_Position = writer.BaseStream.Position; writer.WriteBytesDirect(new Byte[IntegrityCheckValue_Length]); // n or at least 16 Bytes writer.WriteBytesDirect(EncryptionParameters); // m Bytes #endregion #region Serialize StructureVersion, ObjectUUID and the Inner Object writer.WriteBytesDirect(BitConverter.GetBytes(_StructureVersion)); ObjectUUID.Serialize(ref writer); // n or at least 16 Bytes Serialize(ref writer); #endregion _TmpSerializedAGraphStructure = writer.ToArray(); #region Encrypt #endregion #region Add IntegrityCheck if (myIntegrityCheckAlgorithm != null && IntegrityCheckValue_Length > 0) { IntegrityCheckValue = myIntegrityCheckAlgorithm.GetHashValueAsByteArray(_TmpSerializedAGraphStructure); // If the returned array is shorter than expected => pad with 0x00 // And if it is longer just copy the number of expected bytes Array.Copy(IntegrityCheckValue, 0, _TmpSerializedAGraphStructure, IntegrityCheckValue_Position, IntegrityCheckValue.Length); } #endregion isDirty = false; if (myCacheSerializeData) _SerializedAGraphStructure = _TmpSerializedAGraphStructure; return _TmpSerializedAGraphStructure; } catch (SerializationException e) { throw new SerializationException(e.Message, e); } }