Crates.io | onc-rpc |
lib.rs | onc-rpc |
version | 0.3.0 |
source | src |
created_at | 2020-06-09 19:01:30.415196 |
updated_at | 2024-05-13 22:10:04.30672 |
description | Open Network Computing / Sun RPC types and fast serialisation |
homepage | |
repository | https://github.com/domodwyer/onc-rpc |
max_upload_size | |
id | 252011 |
size | 109,750 |
This crate implements the Open Network Computing Remote Procedure Call
system
(originally known as the Sun RPC system) as described in RFC 1831 and RFC
5531.
use onc_rpc::{
auth::{AuthFlavor, AuthUnixParams},
CallBody,
MessageType,
RpcMessage,
};
// Add RPC call authentication.
let auth_params = AuthUnixParams::new(
42, // Stamp
"bananas.local", // Machine name
501, // UID
501, // GID
None, // No additional GIDs
);
// Build a dummy byte payload.
let payload = vec![42, 42, 42, 42];
// Construct the actual RPC message.
let msg = RpcMessage::new(
4242,
MessageType::Call(CallBody::new(
100000, // Program number
42, // Program version
13, // Procedure number
AuthFlavor::AuthUnix(auth_params), // Credentials
AuthFlavor::AuthNone(None), // Response verifier
&payload,
)),
);
// Serialise the RPC message, or serialise_into() to reuse buffers.
let network_buffer = msg.serialise().expect("serialise message");
// And do something with it!
I had no use for the following, however PRs to extend this crate are happily accepted :)
The auth flavors not included in this crate can still be used as the flavor discriminant and associated opaque data is available in the application layer - this crate just lacks pre-defined types to describe them.
Currently a buffer has to be passed to serialise the complete message into a continuous memory region - it would be nicer to support vectorised I/O to provide zero-copy serialisation too.
Included in the fuzz/
directory is a deserialisation fuzzer that attempts to
decode arbitrary inputs, and if successful serialises the resulting message and
compares the result with the input.
Install cargo fuzz
and invoke the fuzzer with cargo fuzz run parse_serialise -- -jobs=30
for parallelised workers.