Ejemplo n.º 1
0
        private async Task <IEnumerable <ICertificate> > GetFromStore(string storeName)
        {
            IEnumerable <ICertificate> certs = null;
            ICertificateStore          store = _storeProvider.Stores.FirstOrDefault(s => s.Name.Equals(storeName, StringComparison.OrdinalIgnoreCase));

            if (store == null)
            {
                throw new NotFoundException(Defines.StoreIdentifier);
            }

            if (Context.Request.Headers.ContainsKey(HeaderNames.Range))
            {
                IEnumerable <ICertificate> certificates = await store.GetCertificates();

                long start, finish, max = certificates.Count();

                if (!Context.Request.Headers.TryGetRange(out start, out finish, max, _units))
                {
                    throw new InvalidRangeException();
                }

                Context.Response.Headers.SetContentRange(start, finish, max);

                certs = certificates.Where((cert, index) => {
                    return(index > start && index <= finish);
                });
            }

            if (certs == null)
            {
                certs = await store.GetCertificates();
            }

            return(certs);
        }
Ejemplo n.º 2
0
        public async Task Head()
        {
            string storeUuid = Context.Request.Query[Defines.StoreIdentifier];
            int    count     = -1;

            if (storeUuid != null)
            {
                StoreId id = StoreId.FromUuid(storeUuid);

                ICertificateStore store = _storeProvider.Stores.FirstOrDefault(s => s.Name.Equals(id.Name, StringComparison.OrdinalIgnoreCase));

                if (store == null)
                {
                    throw new NotFoundException(Defines.StoreIdentifier);
                }

                count = (await store.GetCertificates()).Count();
            }

            if (count == -1)
            {
                count = await SafeGetCertCount();
            }

            this.Context.Response.SetItemsCount(count);
            this.Context.Response.Headers[HeaderNames.AcceptRanges] = _units;
        }
Ejemplo n.º 3
0
 private async Task <IEnumerable <ICertificate> > SafeGetCertificates(ICertificateStore store)
 {
     return((await SafeAccessStore(async() => await store.GetCertificates())) ?? Enumerable.Empty <ICertificate>());
 }