public void ApplyValues(IDictionary <String, String> valueMapper, ISerializer serializer) { String rawByteValue = serializer.Deserialze <String>(valueMapper[nameof(ClientDuid)]); Byte[] parsedBytes = ByteHelper.GetBytesFromHexString(rawByteValue); ClientDuid = DUIDFactory.GetDUID(parsedBytes); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { String rawValue = (String)reader.Value; Byte[] value = Convert.FromBase64String(rawValue); DUID address = DUIDFactory.GetDUID(value); return(address); }
public static DHCPv6PacketIdentifierOption FromByteArray(Byte[] data, Int32 offset) { UInt16 code = ByteHelper.ConvertToUInt16FromByte(data, offset); DUID duid = DUIDFactory.GetDUID(data, offset + 4); if (duid == DUID.Empty) { throw new ArgumentException("duid"); } return(new DHCPv6PacketIdentifierOption(code, duid)); }
public void GetDUID_Unknown() { Random random = new Random(); Byte[] value = random.NextBytes(20); Byte[] input = new byte[2 + value.Length]; input[0] = 0; input[1] = 17; value.CopyTo(input, 2); var duid = DUIDFactory.GetDUID(input, 0); Assert.NotNull(duid); Assert.IsAssignableFrom <UnknownDUID>(duid); Assert.Equal(value, duid.Value); }
public void Add_WithReplace() { Byte newCode = 2; Random random = new Random(); Byte[] value = random.NextBytes(20); Byte[] input = new byte[2 + value.Length]; input[0] = 0; input[1] = newCode; value.CopyTo(input, 2); DUIDFactory.AddDUIDType(newCode, (input) => new FakeDUID(), true); var duid = DUIDFactory.GetDUID(input); Assert.NotNull(duid); Assert.IsAssignableFrom <FakeDUID>(duid); }
public Boolean ArePropertiesAndValuesValid(IDictionary <String, String> valueMapper, ISerializer serializer) { if (valueMapper.ContainsKey(nameof(ClientDuid)) == false) { return(false); } try { String rawByteValue = serializer.Deserialze <String>(valueMapper[nameof(ClientDuid)]); Byte[] parsedBytes = ByteHelper.GetBytesFromHexString(rawByteValue); var duid = DUIDFactory.GetDUID(parsedBytes); return(duid.Type != DUID.DUIDTypes.Unknown); } catch (Exception) { return(false); } }
public void GetDUID_LinkLayerAddressAndTimeDUID() { String rawInput = "00:01:00:01:23:c4:e7:39:00:15:5d:07:e1:12"; Byte[] input = ByteConverter.FromString(rawInput, ':'); Byte[] macAddress = ByteConverter.FromString("00:15:5d:07:e1:12", ':'); DateTime time = new DateTime(2019, 1, 6, 16, 20, 09); var duid = DUIDFactory.GetDUID(input, 0); Assert.NotNull(duid); Assert.IsAssignableFrom <LinkLayerAddressAndTimeDUID>(duid); LinkLayerAddressAndTimeDUID castedDuid = (LinkLayerAddressAndTimeDUID)duid; Assert.Equal(macAddress, castedDuid.LinkLayerAddress); Assert.Equal(LinkLayerAddressDUID.DUIDLinkLayerTypes.Ethernet, castedDuid.LinkType); Assert.Equal(Beer.DaAPI.Core.Common.DUID.DUIDTypes.LinkLayerAndTime, duid.Type); Assert.Equal(time, castedDuid.Time); }
public void Add_AlreadyExists() { Assert.ThrowsAny <Exception>(() => DUIDFactory.AddDUIDType(1, (input) => new FakeDUID(), false)); }