/// <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); }
/// <summary> /// Creates a nuget-package-owners attribute. /// </summary> /// <param name="packageOwners">A read-only list of package owners.</param> /// <returns>An attribute object.</returns> /// <exception cref="ArgumentException">Thrown if <paramref name="packageOwners" /> is either <c>null</c> /// or empty or if any package owner name is invalid.</exception> public static CryptographicAttributeObject CreateNuGetPackageOwners(IReadOnlyList <string> packageOwners) { if (packageOwners == null || packageOwners.Count == 0) { throw new ArgumentException(Strings.ArgumentCannotBeNullOrEmpty, nameof(packageOwners)); } if (packageOwners.Any(packageOwner => string.IsNullOrWhiteSpace(packageOwner))) { throw new ArgumentException(Strings.NuGetPackageOwnersInvalidValue, nameof(packageOwners)); } var nugetPackageOwners = new NuGetPackageOwners(packageOwners); var bytes = nugetPackageOwners.Encode(); return(new CryptographicAttributeObject( new Oid(Oids.NuGetPackageOwners), new AsnEncodedDataCollection(new AsnEncodedData(Oids.NuGetPackageOwners, bytes)))); }