@@ -6086,13 +6086,27 @@ impl EncryptedClient {
60866086 . map_err ( ClientError :: Encryption ) ?;
60876087
60886088 let aead = Aead :: new_default ( & accepted_share. dek ) ;
6089- let version = accepted_share. encryption_version . unwrap_or ( 2 ) ;
6090- let plaintext = if version >= 4 {
6091- let aad = format ! ( "fula:v4:content:{}" , storage_key) . into_bytes ( ) ;
6092- aead. decrypt_with_aad ( & nonce, & data, & aad)
6093- } else {
6094- aead. decrypt ( & nonce, & data)
6095- } . map_err ( ClientError :: Encryption ) ?;
6089+ // `encryption_version` is Option<u8>: Some when the share creator
6090+ // explicitly stamped the token (new fula-flutter builds), None for
6091+ // tokens created between 1b82b95 (inline-nonce support, Jan 2026)
6092+ // and the flutter-side fix (which omit the field). For None, we
6093+ // try v4 AAD first (current upload format) and fall back to the
6094+ // pre-AAD v2 format so legacy tokens still decrypt.
6095+ let aad = format ! ( "fula:v4:content:{}" , storage_key) . into_bytes ( ) ;
6096+ let plaintext = match accepted_share. encryption_version {
6097+ Some ( v) if v >= 4 => aead
6098+ . decrypt_with_aad ( & nonce, & data, & aad)
6099+ . map_err ( ClientError :: Encryption ) ?,
6100+ Some ( _) => aead
6101+ . decrypt ( & nonce, & data)
6102+ . map_err ( ClientError :: Encryption ) ?,
6103+ None => match aead. decrypt_with_aad ( & nonce, & data, & aad) {
6104+ Ok ( pt) => pt,
6105+ Err ( _) => aead
6106+ . decrypt ( & nonce, & data)
6107+ . map_err ( ClientError :: Encryption ) ?,
6108+ } ,
6109+ } ;
60966110
60976111 return Ok ( Bytes :: from ( plaintext) ) ;
60986112 }
0 commit comments