- 
                Notifications
    You must be signed in to change notification settings 
- Fork 101
          feat: Configurable Reader type
          #936
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Closed
      
      
    
  
     Closed
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // Copyright 2025 Adobe. All rights reserved. | ||
| // This file is licensed to you under the Apache License, | ||
| // Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) | ||
| // or the MIT license (http://opensource.org/licenses/MIT), | ||
| // at your option. | ||
|  | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // this software is distributed on an "AS IS" BASIS, WITHOUT | ||
| // WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or | ||
| // implied. See the LICENSE-MIT and LICENSE-APACHE files for the | ||
| // specific language governing permissions and limitations under | ||
| // each license. | ||
|  | ||
| use std::slice::Iter; | ||
|  | ||
| use c2pa_status_tracker::StatusTracker; | ||
| use serde::Serialize; | ||
|  | ||
| use crate::{HashedUri, Manifest, ManifestAssertion, Result}; | ||
|  | ||
| /// A `ReaderConfig` allows a caller to provide additional information | ||
| /// to a [`Reader`] about how the `Reader` should handle specific edge | ||
| /// cases. | ||
| /// | ||
| /// [`Reader`]: crate::Reader | ||
| #[derive(Default)] | ||
| pub struct ReaderConfig { | ||
| assertion_readers: Vec<Box<dyn AssertionReader + 'static>>, | ||
| } | ||
|  | ||
| impl ReaderConfig { | ||
| /// Adds an [`AssertionReader`] to this configuration. | ||
| /// | ||
| /// This configures the reader to process one or more C2PA assertion | ||
| /// types that are not automatically handled by this crate. | ||
| pub fn add_assertion_reader<T: AssertionReader + 'static>(&mut self, assertion_reader: T) { | ||
| self.assertion_readers.push(Box::new(assertion_reader)); | ||
| } | ||
| } | ||
|  | ||
| /// An implementation of `AssertionReader` extends this crate to add | ||
| /// knowledge of one or more C2PA assertion types that are not automatically | ||
| /// handled by this crate. | ||
| pub trait AssertionReader { | ||
| // TO DO: Add an Async variant of this trait once we agree | ||
| // on basics. | ||
|  | ||
| /// Return `true` if this implementation can process an assertion of the given type. | ||
| fn can_process_assertion_with_label(&self, label: &str) -> bool; | ||
|  | ||
| /// Check the validity of a [`ManifestAssertion`] and return a | ||
| /// [`Serialize`]-able summary of what was found. | ||
| /// | ||
| /// ## Errors vs Validation Status | ||
| /// | ||
| /// The implementation should, to the maximum extent possible, | ||
| /// report validation errors (including parsing and network errors) | ||
| /// by adding entries to the provided [`StatusTracker`] instance. | ||
| /// | ||
| /// Returning an `Err` result will cause the overall validation process | ||
| /// to fail and should be used only as a last resort. | ||
| /// | ||
| /// In the event of more typical error conditions, the implementation | ||
| /// should return as much of the data as is available and may omit data | ||
| /// that was inaccessible or unavailable. | ||
| fn validate( | ||
| &self, | ||
| manifest: &ReaderManifest, | ||
| assertion: &ManifestAssertion, | ||
| log: Box<&'static mut dyn StatusTracker>, | ||
| // ^^ PROBLEM: StatusTracker can't be made into an object | ||
| ) -> Result<Box<dyn Serialize>>; | ||
| // ^^ PROBLEM: Serialize can't be made into an object | ||
| } | ||
|  | ||
| /// A `ReaderManifest` contains a preliminary description of a C2PA Manifest which can be inspected by the [`AssertionReader`] in its [`validate`] method. | ||
| /// | ||
| /// [`validate`]: AssertionReader::validate | ||
| pub struct ReaderManifest<'a> { | ||
| manifest: &'a Manifest, // private: could be replaced by anything | ||
| } | ||
|  | ||
| impl<'a> ReaderManifest<'a> { | ||
| /// Return an iterator over the assertions in this manifest. | ||
| pub fn assertions(&'a self) -> Iter<'a, HashedUri> { | ||
| todo!(); | ||
| } | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only did it for this one, but I would anticipate doing this same default vs configurable approach for the other entry points.