From d087166c51f2452aa0544b4bc74253bdef7a6aec Mon Sep 17 00:00:00 2001 From: oblivious-app <55861861+oblivious-app@users.noreply.github.com> Date: Fri, 18 Sep 2020 00:27:17 -0700 Subject: [PATCH] add to_bits_be --- r1cs-std/src/bits/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/r1cs-std/src/bits/mod.rs b/r1cs-std/src/bits/mod.rs index 03b10c9..745ae5c 100644 --- a/r1cs-std/src/bits/mod.rs +++ b/r1cs-std/src/bits/mod.rs @@ -25,13 +25,27 @@ pub trait ToBitsGadget { /// This is the correct default for 99% of use cases. fn to_bits_le(&self) -> Result>, SynthesisError>; - /// Outputs a possibly non-unique bit-wise representation of `self`. + /// Outputs a possibly non-unique little-endian bit-wise representation of `self`. /// /// If you're not absolutely certain that your usecase can get away with a /// non-canonical representation, please use `self.to_bits()` instead. fn to_non_unique_bits_le(&self) -> Result>, SynthesisError> { self.to_bits_le() } + + /// Outputs the canonical big-endian bit-wise representation of `self`. + fn to_bits_be(&self) -> Result>, SynthesisError> { + let mut res = self.to_bits_le()?; + res.reverse(); + Ok(res) + } + + /// Outputs a possibly non-unique big-endian bit-wise representation of `self`. + fn to_non_unique_bits_be(&self) -> Result>, SynthesisError> { + let mut res = self.to_non_unique_bits_le()?; + res.reverse(); + Ok(res) + } } impl ToBitsGadget for Boolean {