joplin_reader/
lib.rs

1//! # joplin-reader
2//! Read-only library for joplin data folders.
3//!
4//! ## Usage
5//!
6//! Decrypt a file loaded into a string:
7//! ```rust
8//! use joplin_reader::notebook::JoplinNotebook;
9//! 
10//! # fn main() -> Result<(), SjclError> {
11//! let joplin_folder = "./Joplin";
12//! // I usually take a ';'-separated list of id,password pairs.
13//! let passwords = "3336eb7a2472d9ae4a690a978fa8a46f,plaintext_password".split(";");
14//! let notebooks = JoplinNotebook::new(joplin_folder, passwords)?;
15//! println!("{:?}", notebooks.read_note("9a20a9e4d336de70cb6d22a58a3e673c"));
16//! # Ok(())
17//! # }
18//! ```
19//!
20
21pub mod key;
22pub mod note;
23pub mod notebook;
24
25use thiserror::Error;
26#[derive(Error, Debug)]
27pub enum JoplinReaderError {
28    #[error("Failed to read joplin folder")]
29    FolderReadError,
30    #[error("Failed to read file: {message:?}")]
31    FileReadError { message: String },
32    #[error("Failed to decrypt: {message:?}")]
33    DecryptionError { message: String },
34    #[error("Note `{note_id:?}` not found")]
35    NoteIdNotFound { note_id: String },
36    #[error("No note with text `{search_text:?}` found")]
37    NoteNotFound { search_text: String },
38    #[error("Invalid format: {message:?}")]
39    InvalidFormat { message: String },
40    #[error("Encryption key `{key:?}` not found")]
41    NoEncryptionKey { key: String },
42    #[error("No encryption text provided")]
43    NoEncryptionText,
44    #[error("No text found")]
45    NoText,
46    #[error("Unexpected end of note")]
47    UnexpectedEndOfNote,
48    #[error("Unknown encryption method")]
49    UnknownEncryptionMethod,
50    #[error("Key id mismatch")]
51    KeyIdMismatch,
52}
53
54#[cfg(test)]
55mod tests {
56    #[test]
57    fn it_works() {
58        assert_eq!(2 + 2, 4);
59    }
60}