QPDFWriter::interpretR3EncryptionParameters(
    std::set<int>& clear,
    char const* user_password, char const* owner_password,
    bool allow_accessibility, bool allow_extract,
    bool allow_assemble, bool allow_annotate_and_form,
    bool allow_form_filling, bool allow_modify_other,
    qpdf_r3_print_e print, qpdf_r3_modify_e modify)
{
    // Acrobat 5 security options:

    // Checkboxes:
    //   Enable Content Access for the Visually Impaired
    //   Allow Content Copying and Extraction

    // Allowed changes menu:
    //   None
    //   Only Document Assembly
    //   Only Form Field Fill-in or Signing
    //   Comment Authoring, Form Field Fill-in or Signing
    //   General Editing, Comment and Form Field Authoring

    // Allowed printing menu:
    //   None
    //   Low Resolution
    //   Full printing

    // Meanings of bits in P when R >= 3
    //
    //  3: low-resolution printing
    //  4: document modification except as controlled by 6, 9, and 11
    //  5: extraction
    //  6: add/modify annotations (comment), fill in forms
    //     if 4+6 are set, also allows modification of form fields
    //  9: fill in forms even if 6 is clear
    // 10: accessibility; ignored by readers, should always be set
    // 11: document assembly even if 4 is clear
    // 12: high-resolution printing

    if (! allow_accessibility)
    {
        // setEncryptionParameters sets this if R > 3
	clear.insert(10);
    }
    if (! allow_extract)
    {
	clear.insert(5);
    }

    // Note: these switch statements all "fall through" (no break
    // statements).  Each option clears successively more access bits.
    switch (print)
    {
      case qpdf_r3p_none:
	clear.insert(3);	// any printing

      case qpdf_r3p_low:
	clear.insert(12);	// high resolution printing

      case qpdf_r3p_full:
	break;

	// no default so gcc warns for missing cases
    }

    // Modify options. The qpdf_r3_modify_e options control groups of
    // bits and lack the full flexibility of the spec. This is
    // unfortunate, but it's been in the API for ages, and we're stuck
    // with it. See also allow checks below to control the bits
    // individually.

    // NOT EXERCISED IN TEST SUITE
    switch (modify)
    {
      case qpdf_r3m_none:
	clear.insert(11);	// document assembly

      case qpdf_r3m_assembly:
	clear.insert(9);	// filling in form fields

      case qpdf_r3m_form:
	clear.insert(6);	// modify annotations, fill in form fields

      case qpdf_r3m_annotate:
	clear.insert(4);	// other modifications

      case qpdf_r3m_all:
	break;

	// no default so gcc warns for missing cases
    }
    // END NOT EXERCISED IN TEST SUITE

    if (! allow_assemble)
    {
        clear.insert(11);
    }
    if (! allow_annotate_and_form)
    {
        clear.insert(6);
    }
    if (! allow_form_filling)
    {
        clear.insert(9);
    }
    if (! allow_modify_other)
    {
        clear.insert(4);
    }
}
QPDFWriter::interpretR3EncryptionParameters(
    std::set<int>& clear,
    char const* user_password, char const* owner_password,
    bool allow_accessibility, bool allow_extract,
    bool allow_assemble, bool allow_annotate_and_form,
    bool allow_form_filling, bool allow_modify_other,
    qpdf_r3_print_e print, qpdf_r3_modify_e modify)
{
     

     
     
     

     
     
     
     
     
     

     
     
     
     

     
     
     
     
     
     
     
     
     
     
     

    if (! allow_accessibility)
    {
         
	clear.insert(10);
    }
    if (! allow_extract)
    {
	clear.insert(5);
    }

     
     
    switch (print)
    {
      case qpdf_r3p_none:
	clear.insert(3);	 

      case qpdf_r3p_low:
	clear.insert(12);	 

      case qpdf_r3p_full:
	break;

	 
    }

     
     
     
     
     

     
    switch (modify)
    {
      case qpdf_r3m_none:
	clear.insert(11);	 

      case qpdf_r3m_assembly:
	clear.insert(9);	 

      case qpdf_r3m_form:
	clear.insert(6);	 

      case qpdf_r3m_annotate:
	clear.insert(4);	 

      case qpdf_r3m_all:
	break;

	 
    }
     

    if (! allow_assemble)
    {
        clear.insert(11);
    }
    if (! allow_annotate_and_form)
    {
        clear.insert(6);
    }
    if (! allow_form_filling)
    {
        clear.insert(9);
    }
    if (! allow_modify_other)
    {
        clear.insert(4);
    }
}