online_security_project/server/Data.cs

27 lines
834 B
C#
Raw Permalink Normal View History

using System.Collections.Generic;
using System.Security.Cryptography;
namespace server;
public class Data
{
public Dictionary<string, RSA> Keys { set; get; } = [];
public Dictionary<string, Queue<byte[]>> Messages { set; get; } = [];
public RSA? GetKey(string Phone) {
return Keys.TryGetValue(Phone, out RSA? value) ? value : null;
}
public Queue<byte[]>? GetMessages(string Phone) {
// Check we have a RSA key for the phone and get the messages
if(!Keys.ContainsKey(Phone)) { return null; }
if(Messages.TryGetValue(Phone, out Queue<byte[]>? value)) {
return value;
}
else {
// generate a new queue because one doesnt already exists
Messages[Phone] = new Queue<byte[]>();
return Messages[Phone];
}
}
}