Class: C2PA::Config
- Inherits:
-
Object
- Object
- C2PA::Config
- Defined in:
- lib/c2pa/config.rb
Overview
Settings that govern how c2pa-rs validates.
These reach the SDK through its Context, which is rebuilt whenever they change. Signing already in flight on another thread continues against the settings it started with.
Defaults are c2pa-rs's own, so a gem that never calls C2PA.configure behaves exactly as it did before this existed.
Instance Attribute Summary collapse
-
#allowed_certificates ⇒ Object
Explicitly allowed certificates, as a PEM bundle.
-
#ocsp_fetch ⇒ Object
Whether to check certificate revocation over OCSP, which also makes network requests.
-
#remote_manifest_fetch ⇒ Object
Whether reading an asset may fetch a manifest over the network.
-
#thumbnail_format ⇒ Object
:jpeg, :png or :gif.
-
#thumbnail_quality ⇒ Object
:low, :medium or :high.
-
#thumbnail_size ⇒ Object
Longest edge of the thumbnail in pixels.
-
#thumbnails ⇒ Object
Whether to embed a thumbnail of the asset in its manifest, and of each ingredient supplied as a file.
-
#trust_anchors ⇒ Object
Additional root certificates to trust, as a PEM bundle.
-
#trust_list ⇒ Object
The trust list proper — normally the C2PA-recognised anchors.
-
#verify_trust ⇒ Object
Whether to check certificates against the trust list at all.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#to_json ⇒ String
The settings document c2pa-rs expects.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/c2pa/config.rb', line 62 def initialize @trust_anchors = nil @trust_list = nil @allowed_certificates = nil @verify_trust = nil @remote_manifest_fetch = nil @ocsp_fetch = nil @thumbnails = false @thumbnail_size = nil @thumbnail_format = nil @thumbnail_quality = nil end |
Instance Attribute Details
#allowed_certificates ⇒ Object
Explicitly allowed certificates, as a PEM bundle.
24 25 26 |
# File 'lib/c2pa/config.rb', line 24 def allowed_certificates @allowed_certificates end |
#ocsp_fetch ⇒ Object
Whether to check certificate revocation over OCSP, which also makes network requests.
39 40 41 |
# File 'lib/c2pa/config.rb', line 39 def ocsp_fetch @ocsp_fetch end |
#remote_manifest_fetch ⇒ Object
Whether reading an asset may fetch a manifest over the network. c2pa-rs defaults this to true, so reading can make an outbound request.
35 36 37 |
# File 'lib/c2pa/config.rb', line 35 def remote_manifest_fetch @remote_manifest_fetch end |
#thumbnail_format ⇒ Object
:jpeg, :png or :gif. Left unset, c2pa-rs picks the smaller encoding.
57 58 59 |
# File 'lib/c2pa/config.rb', line 57 def thumbnail_format @thumbnail_format end |
#thumbnail_quality ⇒ Object
:low, :medium or :high. c2pa-rs's default is :medium.
60 61 62 |
# File 'lib/c2pa/config.rb', line 60 def thumbnail_quality @thumbnail_quality end |
#thumbnail_size ⇒ Object
Longest edge of the thumbnail in pixels. c2pa-rs's default is 1024.
54 55 56 |
# File 'lib/c2pa/config.rb', line 54 def thumbnail_size @thumbnail_size end |
#thumbnails ⇒ Object
Whether to embed a thumbnail of the asset in its manifest, and of each ingredient supplied as a file.
Off by default, which departs from c2pa-rs. Its thumbnail generation scales to a fixed long edge and upscales to reach it, so a 160x120 image gets a 1024x768 thumbnail ten times its own size. Turn it on for assets that are larger than thumbnail_size, or set thumbnail_size to suit.
Thumbnails are produced for JPEG, PNG, WebP and TIFF. Other formats are signed without one; c2pa-rs treats that as non-fatal.
51 52 53 |
# File 'lib/c2pa/config.rb', line 51 def thumbnails @thumbnails end |
#trust_anchors ⇒ Object
Additional root certificates to trust, as a PEM bundle. Use this for a private or enterprise CA: a certificate chaining to one of these validates as "Trusted" rather than carrying signingCredential.untrusted.
16 17 18 |
# File 'lib/c2pa/config.rb', line 16 def trust_anchors @trust_anchors end |
#trust_list ⇒ Object
The trust list proper — normally the C2PA-recognised anchors. Setting this replaces that list rather than adding to it, so prefer trust_anchors unless you mean to substitute the whole thing.
21 22 23 |
# File 'lib/c2pa/config.rb', line 21 def trust_list @trust_list end |
#verify_trust ⇒ Object
Whether to check certificates against the trust list at all.
Turning this off means nothing is ever reported as untrusted, which in a library for establishing provenance is rarely what you want. It exists for offline and air-gapped environments.
31 32 33 |
# File 'lib/c2pa/config.rb', line 31 def verify_trust @verify_trust end |
Instance Method Details
#to_json ⇒ String
The settings document c2pa-rs expects.
Only values that were actually set are included, so anything left alone keeps the SDK's default rather than being pinned to ours.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/c2pa/config.rb', line 81 def to_json trust = {} trust["user_anchors"] = read_pem(@trust_anchors) unless @trust_anchors.nil? trust["trust_anchors"] = read_pem(@trust_list) unless @trust_list.nil? trust["allowed_list"] = read_pem(@allowed_certificates) unless @allowed_certificates.nil? verify = {} verify["verify_trust"] = @verify_trust unless @verify_trust.nil? verify["remote_manifest_fetch"] = @remote_manifest_fetch unless @remote_manifest_fetch.nil? verify["ocsp_fetch"] = @ocsp_fetch unless @ocsp_fetch.nil? # enabled is always sent: this gem's default differs from c2pa-rs's, so # leaving it out would mean inheriting the wrong one. thumbnail = { "enabled" => @thumbnails == true } thumbnail["long_edge"] = Integer(@thumbnail_size) unless @thumbnail_size.nil? thumbnail["format"] = @thumbnail_format.to_s.downcase unless @thumbnail_format.nil? thumbnail["quality"] = @thumbnail_quality.to_s.downcase unless @thumbnail_quality.nil? settings = { "builder" => { "thumbnail" => thumbnail } } settings["trust"] = trust unless trust.empty? settings["verify"] = verify unless verify.empty? JSON.generate(settings) end |