# DigestedData and AuthenticatedData
## DigestedData
`DigestedData` implements RFC 5652 §7 — hash-protected content.
```python
class DigestedData:
@staticmethod
def from_der(data: bytes) -> DigestedData: ...
def to_der(self) -> bytes: ...
version: int
digest_algorithm_oid: ObjectIdentifier
digest_algorithm_params: bytes | None
encap_content_type: ObjectIdentifier
encap_content: bytes | None
digest: bytes
```
### Usage
```python
from synta.cms import DigestedData
dd = DigestedData.from_der(data)
print(f"digest algorithm: {dd.digest_algorithm_oid}")
print(f"digest: {dd.digest.hex()}")
if dd.encap_content:
content = dd.encap_content # raw content bytes
```
---
## AuthenticatedData
`AuthenticatedData` implements RFC 5652 §9 — MAC-authenticated content.
```python
class AuthenticatedData:
@staticmethod
def from_der(data: bytes) -> AuthenticatedData: ...
def to_der(self) -> bytes: ...
version: int
originator_info: bytes | None
recipient_infos: bytes # raw RecipientInfos SET bytes
mac_algorithm_oid: ObjectIdentifier
mac_algorithm_params: bytes | None
digest_algorithm_oid: ObjectIdentifier | None
digest_algorithm_params: bytes | None
encap_content_type: ObjectIdentifier
encap_content: bytes | None
mac: bytes
auth_attrs: bytes | None
# Value bytes of the [2] IMPLICIT AuthAttributes (no outer tag/length).
# To hash for MAC verification, prepend b'\x31' + DER-encoded length header.
unauth_attrs: bytes | None
# Value bytes of the [3] IMPLICIT UnauthAttributes (no outer tag/length).
```
### Usage
```python
from synta.cms import AuthenticatedData
ad = AuthenticatedData.from_der(data)
print(f"mac algorithm: {ad.mac_algorithm_oid}")
print(f"mac: {ad.mac.hex()}")
if ad.auth_attrs:
# auth_attrs contains only the value bytes of the AuthAttributes SET (no outer
# tag or length). To compute the MAC input, prepend b'\x31' + a properly
# DER-encoded length header. Individual Attribute SEQUENCES can be iterated
# directly from the value bytes:
import synta
dec = synta.Decoder(ad.auth_attrs, synta.Encoding.DER)
while not dec.is_empty():
attr_tlv = dec.decode_raw_tlv()
# each attr_tlv is a complete Attribute SEQUENCE
```
See also [CMS Overview](overview.md) for the complete list of content types.