public EncriptionKey ReadValue(ReadOnlySpan <byte> data) { var remainingSlice = data; //header SerializationHelpers.ParseRequiredHeader("Encription key field", remainingSlice, HeaderBytes); remainingSlice = remainingSlice.Slice(HeaderBytes.Length); var encKey = new EncriptionKey(); // Type var indexOfEnd = remainingSlice.IndexOf(SDPSerializer.ByteColon); // Only method must be present if (indexOfEnd == -1) { encKey.Method = SerializationHelpers.ParseRequiredString("Encription key field: method", remainingSlice); return(encKey); } else { encKey.Method = SerializationHelpers.ParseRequiredString("Encription key field: method", remainingSlice.Slice(0, indexOfEnd)); encKey.Value = SerializationHelpers.ParseRequiredString("Encription key field: value", remainingSlice.Slice(indexOfEnd + 1)); } return(encKey); }
public void CanDeSerialize() { var field = "k=clear:secretkey".ToByteArray(); var result = EncriptionKeySerializer.Instance.ReadValue(field); var expected = new EncriptionKey() { Method = EncriptionKey.ClearMethod, Value = "secretkey" }; Assert.True(CheckIfConnectionDatasAreSame(expected, result)); }
public EncriptionFile GetEncriptedFile(EncriptionKey Key) { var Efile = new EncriptionFile(Key); if (File.Exists(Key.Loads)) { Efile.Description = File.ReadAllText(Key.Loads); } else { File.WriteAllText(Efile.Loads, Efile.Description); } return(Efile); }
public void Post(string id) { Card cards = JsonConvert.DeserializeObject <Card>(id); var board = _cache.Get <Board>("currentState"); BoardManager.SetCardToNewLane(board, cards.ID, cards.CardProgress); _cache.Set("currentState", board, TimeSpan.FromDays(1)); var serlizedList = JsonConvert.SerializeObject(board.AllCards); string allText = System.IO.File.ReadAllText("configuration.json"); EncriptionKey key = JsonConvert.DeserializeObject <EncriptionKey>(allText); var filekey = Encription.GetEncriptedFile(key); filekey.Description = serlizedList; Encription.EncriptedFile(filekey); Encription.SaveDataSet(filekey); }
public async Task CanSerialize() { var expected = $"k=clear:secretkey{SDPLib.SDPSerializer.CRLF}".ToByteArray(); var pipe = new Pipe(); var value = new EncriptionKey() { Method = EncriptionKey.ClearMethod, Value = "secretkey" }; EncriptionKeySerializer.Instance.WriteValue(pipe.Writer, value); pipe.Writer.Complete(); var serialized = (await pipe.Reader.ReadAsync()).Buffer.ToArray(); Assert.Equal(expected, serialized); }
public void WriteValue(IBufferWriter <byte> writer, EncriptionKey value) { if (value == null) { return; } SerializationHelpers.EnsureFieldIsPresent("Encription key field: method", value.Method); SerializationHelpers.CheckForReserverdChars("Encription key field: method", value.Method, ReservedChars); writer.WriteString($"k={value.Method}"); if (value.Value != null) { SerializationHelpers.CheckForReserverdChars("Encription key field: value", value.Value, ReservedChars); writer.WriteString($":{value.Value}"); } writer.WriteString(SDPSerializer.CRLF); }
public Board Get() { string allText = System.IO.File.ReadAllText("configuration.json"); EncriptionKey key = JsonConvert.DeserializeObject <EncriptionKey>(allText); var filekey = Encription.GetEncriptedFile(key); Encription.DeEncriptedFile(filekey); List <Card> cards = JsonConvert.DeserializeObject <List <Card> >(filekey.Description); if (cards == null) { cards = new List <Card>(); } Board board = BoardManager.SetUpBoard(cards); _cache.Set("currentState", board, TimeSpan.FromDays(1)); //return View(personlist); return(board); }
public void Put(string id) { // Card cards = value; Card cards = JsonConvert.DeserializeObject <Card>(id); cards.CardProgress = LaneType.Backlog; cards.Date = DateTime.Now.ToShortDateString(); var board = _cache.Get <Board>("currentState"); cards.ID = board.LastID + 1; board.LastID = cards.ID; BoardManager.AddCardToBoard(board, cards); _cache.Set("currentState", board, TimeSpan.FromDays(1)); var serlizedList = JsonConvert.SerializeObject(board.AllCards); string allText = System.IO.File.ReadAllText("configuration.json"); EncriptionKey key = JsonConvert.DeserializeObject <EncriptionKey>(allText); var filekey = Encription.GetEncriptedFile(key); filekey.Description = serlizedList; Encription.EncriptedFile(filekey); Encription.SaveDataSet(filekey); }
private bool CheckIfConnectionDatasAreSame(EncriptionKey expected, EncriptionKey result) { return(expected.Method == result.Method && expected.Value == result.Value); }