mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-26 00:48:39 +00:00
Rust Flatbuffers Verifier (#6269)
* Updated comments and fixed a fundemental type error. * bump rust flatbuffers semver * Initial commit with verifier, need to clean up * Verifier tested. Needs clean up and refactoring. * Display for InvalidFlatbuffer and better errors for strings * SimpleToVerify, some refactoring * Combined VerifierType TableAccessorFuncBody into FollowType * scrub todos * Update Rust get_root functions. There are 6 variants, with verifier options, default verifier options and no verification "fast". * Rename root fns * inline * Update to use thiserror * fix for bad compiler * improve error formatting * Replace multiply with saturating_multiply * saturating adds too * Add docs disclaiming experimental verification system Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
@@ -77,7 +77,8 @@ impl<'a> flatbuffers::Follow<'a> for EnumInNestedNS {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self(flatbuffers::read_scalar_at::<i8>(buf, loc))
|
||||
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,14 +93,27 @@ impl flatbuffers::Push for EnumInNestedNS {
|
||||
impl flatbuffers::EndianScalar for EnumInNestedNS {
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
Self(i8::to_le(self.0))
|
||||
let b = i8::to_le(self.0);
|
||||
Self(b)
|
||||
}
|
||||
#[inline]
|
||||
fn from_little_endian(self) -> Self {
|
||||
Self(i8::from_le(self.0))
|
||||
let b = i8::from_le(self.0);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for EnumInNestedNS {
|
||||
#[inline]
|
||||
fn run_verifier<'o, 'b>(
|
||||
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
i8::run_verifier(v, pos)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for EnumInNestedNS {}
|
||||
// struct StructInNestedNS, aligned to 4
|
||||
#[repr(C, align(4))]
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
@@ -116,6 +130,7 @@ impl std::fmt::Debug for StructInNestedNS {
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for StructInNestedNS {}
|
||||
impl flatbuffers::SafeSliceAccess for StructInNestedNS {}
|
||||
impl<'a> flatbuffers::Follow<'a> for StructInNestedNS {
|
||||
type Inner = &'a StructInNestedNS;
|
||||
@@ -153,7 +168,15 @@ impl<'b> flatbuffers::Push for &'b StructInNestedNS {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for StructInNestedNS {
|
||||
#[inline]
|
||||
fn run_verifier<'o, 'b>(
|
||||
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.in_buffer::<Self>(pos)
|
||||
}
|
||||
}
|
||||
impl StructInNestedNS {
|
||||
pub fn new(_a: i32, _b: i32) -> Self {
|
||||
StructInNestedNS {
|
||||
@@ -217,6 +240,18 @@ impl<'a> TableInNestedNS<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for TableInNestedNS<'_> {
|
||||
#[inline]
|
||||
fn run_verifier<'o, 'b>(
|
||||
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.visit_field::<i32>(&"foo", Self::VT_FOO, false)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct TableInNestedNSArgs {
|
||||
pub foo: i32,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user