Skip to content

Commit dee0f65

Browse files
committed
chore: use #![deny(missing_docs)] to force documentation of public APIs.
1 parent 482156c commit dee0f65

File tree

7 files changed

+49
-5
lines changed

7 files changed

+49
-5
lines changed

capi/include/yara_x.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
// constructs that YARA-X doesn't accept by default.
3434
#define YRX_RELAXED_RE_SYNTAX 2
3535

36+
// Error codes returned by functions in this API.
3637
typedef enum YRX_RESULT {
3738
// Everything was OK.
3839
SUCCESS,
@@ -78,7 +79,9 @@ typedef struct YRX_BUFFER {
7879

7980
// Contains information about a pattern match.
8081
typedef struct YRX_MATCH {
82+
// Offset within the data where the match occurred.
8183
size_t offset;
84+
// Length of the match.
8285
size_t length;
8386
} YRX_MATCH;
8487

capi/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ includes:
8888
[4]: https://learn.microsoft.com/en-us/cpp/build/reference/module-definition-dot-def-files
8989
*/
9090

91+
#![deny(missing_docs)]
9192
#![allow(non_camel_case_types)]
9293
#![allow(clippy::missing_safety_doc)]
9394
#![allow(clippy::not_unsafe_ptr_arg_deref)]
@@ -110,6 +111,7 @@ thread_local! {
110111
static LAST_ERROR: RefCell<Option<CString>> = RefCell::new(None);
111112
}
112113

114+
/// Error codes returned by functions in this API.
113115
#[repr(C)]
114116
pub enum YRX_RESULT {
115117
/// Everything was OK.
@@ -190,7 +192,9 @@ impl Drop for YRX_PATTERN {
190192
/// Contains information about a pattern match.
191193
#[repr(C)]
192194
pub struct YRX_MATCH {
195+
/// Offset within the data where the match occurred.
193196
pub offset: usize,
197+
/// Length of the match.
194198
pub length: usize,
195199
}
196200

lib/src/compiler/errors.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ use yara_x_parser::Error as ParseError;
1313
/// Errors returned while serializing/deserializing compiled rules.
1414
#[derive(Error, Debug)]
1515
pub enum SerializationError {
16+
/// The data being deserialized doesn't contain YARA-X serialized rules.
1617
#[error("not a YARA-X compiled rules file")]
1718
InvalidFormat,
1819

20+
/// The data seems to be YARA-X serialized rules, but it's invalid or
21+
/// corrupted.
1922
#[error("invalid YARA-X compiled rules file")]
2023
InvalidEncoding(#[from] bincode::Error),
2124

25+
/// I/O error while trying to read or write serialized data.
2226
#[error(transparent)]
2327
IoError(#[from] io::Error),
2428
}
@@ -31,6 +35,7 @@ pub struct EmitWasmError(#[from] anyhow::Error);
3135

3236
/// Errors returned by the compiler.
3337
#[derive(Error, Debug, Eq, PartialEq)]
38+
#[allow(missing_docs)]
3439
pub enum Error {
3540
#[error(transparent)]
3641
ParseError(#[from] ParseError),
@@ -44,6 +49,7 @@ pub enum Error {
4449

4550
/// An error occurred during the compilation process.
4651
#[derive(DeriveError, Eq, PartialEq)]
52+
#[allow(missing_docs)]
4753
#[non_exhaustive]
4854
pub enum CompileError {
4955
#[error("wrong type")]

lib/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ assert_eq!(results.matching_rules().len(), 1);
4141
```
4242
*/
4343

44+
#![deny(missing_docs)]
45+
4446
pub use compiler::compile;
4547
pub use compiler::CompileError;
4648
pub use compiler::Compiler;

lib/src/scanner/mod.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,34 @@ pub enum ScanError {
5252
Timeout,
5353
/// Could not open the scanned file.
5454
#[error("can not open `{path}`: {source}")]
55-
OpenError { path: PathBuf, source: std::io::Error },
55+
OpenError {
56+
/// Path of the file being scanned.
57+
path: PathBuf,
58+
/// Error that occurred.
59+
source: std::io::Error,
60+
},
5661
/// Could not map the scanned file into memory.
5762
#[error("can not map `{path}`: {source}")]
58-
MapError { path: PathBuf, source: fmmap::error::Error },
63+
MapError {
64+
/// Path of the file being scanned.
65+
path: PathBuf,
66+
/// Error that occurred.
67+
source: fmmap::error::Error,
68+
},
5969
/// Could not deserialize the protobuf message for some YARA module.
6070
#[error("can not deserialize protobuf message for YARA module `{module}`: {err}")]
61-
ProtoError { module: String, err: protobuf::Error },
71+
ProtoError {
72+
/// Module name.
73+
module: String,
74+
/// Error that occurred
75+
err: protobuf::Error,
76+
},
6277
/// The module is unknown.
6378
#[error("unknown module `{module}`")]
64-
UnknownModule { module: String },
79+
UnknownModule {
80+
/// Module name.
81+
module: String,
82+
},
6583
}
6684

6785
/// Global counter that gets incremented every 1 second by a dedicated thread.

lib/src/variables.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ pub enum VariableError {
6161
"invalid type for `{variable}`, expecting `{expected_type}`, got `{actual_type}"
6262
)]
6363
InvalidType {
64+
/// Variable name.
6465
variable: String,
66+
/// Name of the expected type.
6567
expected_type: String,
68+
/// Name of the actual type.
6669
actual_type: String,
6770
},
6871
}
@@ -334,7 +337,7 @@ pub fn is_valid_identifier(ident: &str) -> bool {
334337
return false;
335338
}
336339

337-
// The the remaining characters must be letters, numbers, or underscores.
340+
// The remaining characters must be letters, numbers, or underscores.
338341
chars.all(|c| c.is_alphanumeric() || c == '_')
339342
}
340343

py/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ rules = yara_x.compile('rule test {strings: $a = "dummy" condition: $a}')
1212
matches = rules.scan(b'some dummy data')
1313
```
1414
*/
15+
16+
#![deny(missing_docs)]
17+
1518
use std::marker::PhantomPinned;
1619
use std::mem;
1720
use std::ops::Deref;
@@ -366,10 +369,15 @@ impl Pattern {
366369
}
367370
}
368371

372+
/// Represents a match found for a pattern.
369373
#[pyclass]
370374
struct Match {
375+
/// Offset within the scanned data where the match occurred.
371376
offset: usize,
377+
/// Length of the match.
372378
length: usize,
379+
/// For patterns that have the `xor` modifier, contains the XOR key that
380+
/// applied to matching data. For any other pattern will be `None`.
373381
xor_key: Option<u8>,
374382
}
375383

0 commit comments

Comments
 (0)