Пример #1
0
        /// <summary>
        ///     Merges the properties from the <see cref="entity" /> into this entity
        /// </summary>
        /// <param name="entity">The entity to merge</param>
        public override void Merge(KeyedEntity entity)
        {
            Guard.NotNull(() => entity, entity);

            var mergeEntity = entity as OAuthCryptoKeyEntity;

            if (mergeEntity == null)
            {
                return;
            }

            IOAuthCryptoKey thisDto  = ToDto();
            IOAuthCryptoKey mergeDto = mergeEntity.ToDto();

            // Compare to see if we need to update changed values (null) values are ignored in persistence
            thisDto.Bucket     = mergeDto.Bucket.HasValue() ? mergeDto.Bucket : thisDto.Bucket;
            thisDto.Handle     = mergeDto.Handle.HasValue() ? mergeDto.Handle : thisDto.Handle;
            thisDto.Key        = mergeDto.Key ?? thisDto.Key;
            thisDto.ExpiresUtc = mergeDto.ExpiresUtc.HasValue() ? mergeDto.ExpiresUtc : thisDto.ExpiresUtc;

            //Convert back to entity
            OAuthCryptoKeyEntity thisEntity = FromDto(thisDto);

            Bucket     = thisEntity.Bucket;
            Handle     = thisEntity.Handle;
            Key        = thisEntity.Key;
            ExpiresUtc = thisEntity.ExpiresUtc;
        }
Пример #2
0
        /// <summary>
        ///     Removes the key from the specified bucket by the specified handle
        /// </summary>
        public void RemoveKey(string bucket, string handle)
        {
            Guard.NotNullOrEmpty(() => bucket, bucket);
            Guard.NotNullOrEmpty(() => handle, handle);

            IOAuthCryptoKey key = GetKeyByBucketHandle(bucket, handle);

            if (key != null)
            {
                Storage.Delete(key.Id);
            }
        }
Пример #3
0
        /// <summary>
        ///     Gets an entity from the <see cref="IOAuthCryptoKey" />.
        /// </summary>
        public static OAuthCryptoKeyEntity FromDto(IOAuthCryptoKey dto)
        {
            Guard.NotNull(() => dto, dto);

            return(new OAuthCryptoKeyEntity
            {
                Id = EntityHelper.SerializeForStorage(dto.Id),
                Bucket = EntityHelper.SerializeForStorage(dto.Bucket),
                Handle = EntityHelper.SerializeForStorage(dto.Handle),
                Key = EntityHelper.SerializeForStorage(dto.Key),
                ExpiresUtc = EntityHelper.SerializeForStorage(dto.ExpiresUtc),
            });
        }
Пример #4
0
        /// <summary>
        ///     Gets the key from the bucket by the specified handle
        /// </summary>
        public CryptoKey GetKey(string bucket, string handle)
        {
            Guard.NotNullOrEmpty(() => bucket, bucket);
            Guard.NotNullOrEmpty(() => handle, handle);

            IOAuthCryptoKey key = GetKeyByBucketHandle(bucket, handle);

            if (key != null)
            {
                return(new CryptoKey(key.Key, key.ExpiresUtc));
            }

            return(null);
        }