Exemplo n.º 1
0
        public async Task <E2EUser> GetUserById(string userId)
        {
            Guid.Parse(userId);

            await SemaphoreSlim.WaitAsync();

            try
            {
                var contact = await this.contacts.Get(userId);

                Debug.Assert(contact.Id == userId);
                E2EUser user = E2EUserSerializer.Deserialize(contact.CryptographicInformation);
                if (user == null) // for example, when the contact has just been added
                {
                    user = new E2EUser {
                        DynamicPrivateDecryptionKeys = new Dictionary <long, byte[]>()
                    }
                }
                ;
                user.UserId          = userId;
                user.StaticPublicKey = contact.StaticPublicKey;
                return(user);
            }
            finally
            {
                SemaphoreSlim.Release();
            }
        }
Exemplo n.º 2
0
        public async Task UpdateUser(E2EUser user)
        {
            Guid.Parse(user.UserId);

            await SemaphoreSlim.WaitAsync();

            try
            {
                Identity contact = await this.contacts.Get(user.UserId);

                var serialized = E2EUserSerializer.Serialize(user);
                contact.CryptographicInformation = serialized;
                await this.contacts.Update(contact);
            }
            finally
            {
                SemaphoreSlim.Release();
            }
        }