Esempio n. 1
0
        /// <summary>
        /// Gets a read-only list of package owners from an optional nuget-package-owners attribute.
        /// </summary>
        /// <param name="signedAttributes">A <see cref="SignerInfo" /> signed attributes collection.</param>
        /// <returns>A read-only list of package owners or <c>null</c>.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="signedAttributes" /> is <c>null</c>.</exception>
        /// <exception cref="SignatureException">Thrown if the attribute does not contain exactly one
        /// attribute value.</exception>
        public static IReadOnlyList <string> GetNuGetPackageOwners(CryptographicAttributeObjectCollection signedAttributes)
        {
            if (signedAttributes == null)
            {
                throw new ArgumentNullException(nameof(signedAttributes));
            }

            var attribute = signedAttributes.GetAttribute(Oids.NuGetPackageOwners);

            if (attribute == null)
            {
                return(null);
            }

            if (attribute.Values.Count != 1)
            {
                throw new SignatureException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              Strings.ExactlyOneAttributeValueRequired,
                              "nuget-package-owners"));
            }

            var nugetPackageOwners = NuGetPackageOwners.Read(attribute.Values[0].RawData);

            return(nugetPackageOwners.PackageOwners);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the V3 service index HTTPS URL from the nuget-v3-service-index-url attribute.
        /// </summary>
        /// <param name="signedAttributes">A <see cref="SignerInfo" /> signed attributes collection.</param>
        /// <returns>The V3 service index HTTPS URL.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="signedAttributes" />
        /// is <c>null</c>.</exception>
        /// <exception cref="SignatureException">Thrown if either exactly one attribute is not present or if
        /// the attribute does not contain exactly one attribute value.</exception>
        public static Uri GetNuGetV3ServiceIndexUrl(CryptographicAttributeObjectCollection signedAttributes)
        {
            if (signedAttributes == null)
            {
                throw new ArgumentNullException(nameof(signedAttributes));
            }

            const string attributeName = "nuget-v3-service-index-url";

            var attribute = signedAttributes.GetAttribute(Oids.NuGetV3ServiceIndexUrl);

            if (attribute == null)
            {
                throw new SignatureException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              Strings.ExactlyOneAttributeRequired,
                              attributeName));
            }

            if (attribute.Values.Count != 1)
            {
                throw new SignatureException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              Strings.ExactlyOneAttributeValueRequired,
                              attributeName));
            }

            var nugetV3ServiceIndexUrl = NuGetV3ServiceIndexUrl.Read(attribute.Values[0].RawData);

            return(nugetV3ServiceIndexUrl.V3ServiceIndexUrl);
        }