Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: mojo/public/rust/src/bindings/encoding.rs

Issue 2220183003: Rust: Add validation to decode (Closed) Base URL: git@github.com:domokit/mojo.git@coder-testing
Patch Set: Pass all tests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 use bindings::mojom::MOJOM_NULL_POINTER; 5 use bindings::mojom::MOJOM_NULL_POINTER;
6 use bindings::util; 6 use bindings::util;
7 7
8 use std::mem; 8 use std::mem;
9 use std::ptr; 9 use std::ptr;
10 use std::ops::{Add, AddAssign, Sub, Mul, Div, Rem}; 10 use std::ops::{Add, AddAssign, Sub, Mul, Div, Rem};
(...skipping 23 matching lines...) Expand all
34 } 34 }
35 35
36 /// Return 1 left-shifted by the amount of bits stored here. 36 /// Return 1 left-shifted by the amount of bits stored here.
37 /// 37 ///
38 /// Only guaranteed to work for up to 8 bits. 38 /// Only guaranteed to work for up to 8 bits.
39 pub fn as_set_bit(self) -> u8 { 39 pub fn as_set_bit(self) -> u8 {
40 debug_assert!(self.0 < 8); 40 debug_assert!(self.0 < 8);
41 1 << (self.0 & 7) 41 1 << (self.0 & 7)
42 } 42 }
43 43
44 pub fn checked_mul(self, val: usize) -> Option<Bits> {
45 match val.checked_mul(self.0) {
46 Some(result) => Some(Bits(result)),
47 None => None,
48 }
49 }
50
44 /// Align the bits to some number of bytes. 51 /// Align the bits to some number of bytes.
45 pub fn align_to_bytes(&mut self, bytes: usize) { 52 pub fn align_to_bytes(&mut self, bytes: usize) {
46 self.0 = util::align_bytes(self.0, 8 * bytes); 53 self.0 = util::align_bytes(self.0, 8 * bytes);
47 } 54 }
48 } 55 }
49 56
50 impl Add for Bits { 57 impl Add for Bits {
51 type Output = Self; 58 type Output = Self;
52 fn add(self, rhs: Self) -> Self { 59 fn add(self, rhs: Self) -> Self {
53 Bits(self.0 + rhs.0) 60 Bits(self.0 + rhs.0)
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } 390 }
384 391
385 /// Signal to finish encoding by destroying the Encoder and returning the fi nal 392 /// Signal to finish encoding by destroying the Encoder and returning the fi nal
386 /// handle vector. 393 /// handle vector.
387 /// 394 ///
388 /// Note: No byte buffer is returned as that is pre-allocated. 395 /// Note: No byte buffer is returned as that is pre-allocated.
389 pub fn unwrap(self) -> Vec<UntypedHandle> { 396 pub fn unwrap(self) -> Vec<UntypedHandle> {
390 self.handles 397 self.handles
391 } 398 }
392 } 399 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698