| 1 |
use crate::errors::{ErrorKind, Result}; |
| 2 |
use crate::one::property_set::PropertySetId; |
| 3 |
use crate::onestore::object::Object; |
| 4 |
|
| 5 |
/// An embedded file data container. |
| 6 |
/// |
| 7 |
/// See [\[MS-ONE\] 2.2.59]. |
| 8 |
/// |
| 9 |
/// [\[MS-ONE\] 2.2.59]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/e2a23dc5-75a5-407f-b5ff-d3412379fa7b |
| 10 |
#[derive(Debug)] |
| 11 |
pub(crate) struct Data(pub(crate) Vec<u8>); |
| 12 |
|
| 13 |
impl Data { |
| 14 |
pub(crate) fn into_value(self) -> Vec<u8> { |
| 15 |
self.0 |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
pub(crate) fn parse(object: &Object) -> Result<Data> { |
| 20 |
if object.id() != PropertySetId::EmbeddedFileContainer.as_jcid() { |
| 21 |
return Err(ErrorKind::MalformedOneNoteFileData( |
| 22 |
format!("unexpected object type: 0x{:X}", object.id().0).into(), |
| 23 |
) |
| 24 |
.into()); |
| 25 |
} |
| 26 |
|
| 27 |
let data = object |
| 28 |
.file_data() |
| 29 |
.ok_or_else(|| { |
| 30 |
ErrorKind::MalformedOneNoteFileData("embedded file container has no data".into()) |
| 31 |
})? |
| 32 |
.to_vec(); |
| 33 |
|
| 34 |
Ok(Data(data)) |
| 35 |
} |