tonhowtf/omniget · error

não montei a cifra

Error message

não montei a cifra: {}

What it means

After picking the encryption version, password_one converts it into an lopdf EncryptionState via EncryptionState::try_from(version). If that conversion fails (unsupported combination of cipher version, filters, or passwords), the error is wrapped as 'não montei a cifra: {}'.

Solutions

  1. Inspect the wrapped inner error message for the exact lopdf rejection reason
  2. Use the default cipher version and "StdCF" string filter as in the surrounding code instead of a custom EncryptionDictionary version
  3. Pin a lopdf version whose EncryptionState::try_from supports your configuration
  4. Shorten passwords if the target revision limits them

Example fix

// before
let state = EncryptionState::try_from(version).map_err(|e| anyhow!("não montei a cifra: {}", e))?;
// after
let state = EncryptionState::try_from(version)
    .map_err(|e| anyhow!("combinação de cifra não suportada ({:?}): {}", version, e))?;
Defensive patterns

Strategy: try-catch

Validate before calling

// stick to the supported combo: default version + StdCF filter + short passwords
assert!(!owner.is_empty());
assert!(owner.len() <= 32, "senha muito longa para AES-128");

Try / catch

let state = EncryptionState::try_from(version)
    .map_err(|e| anyhow!("cifra não suportada nesta versão do lopdf: {}", e))?;

Prevention

When it happens

Trigger: EncryptionState::try_from returns Err — e.g. the chosen cipher version/filter combination is not supported by the installed lopdf version, or password bytes exceed what the cipher revision allows.

Common situations: Upgrading/downgrading lopdf changes which EncryptionState variants are constructible; custom permissions or filter names rejected; extremely long passwords truncated/invalid for RC4/AES-40 revisions.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/13ca4ad3af1dd301. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/pdf_write.rs:169

                Object::Array(vec![
                    Object::string_literal(id.clone()),
                    Object::string_literal(id),
                ]),
            );
        }
        let filter: Arc<dyn CryptFilter> = Arc::new(Aes128CryptFilter);
        let version = EncryptionVersion::V4 {
            document: &doc,
            encrypt_metadata: true,
            crypt_filters: BTreeMap::from([(b"StdCF".to_vec(), filter)]),
            stream_filter: b"StdCF".to_vec(),
            string_filter: b"StdCF".to_vec(),
            owner_password: owner,
            user_password: &opts.user_password,
            permissions: permissions_of(opts),
        };
        let state =
            EncryptionState::try_from(version).map_err(|e| anyhow!("não montei a cifra: {}", e))?;
        doc.encrypt(&state)
            .map_err(|e| anyhow!("não cifrei: {}", e))?;
        note = if opts.user_password.is_empty() {
            "permissões travadas (abre sem senha)".into()
        } else {
            "AES-128, senha para abrir".into()
        };
    }
    let out = out_path(
        input,
        &opts.output_dir,
        &opts.suffix,
        if opts.mode == "remove" {
            "-sem-senha"
        } else {
            "-protegido"
        },
    )?;

View on GitHub (pinned to 8600b91f42)