-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Clean ups * Use generic multiplier * Use bcs * Serde from workspace * remove debug code * docs * fix test * test * Refactor + new serde * challenge size * Default challenge size * clean up * clippy * license * test * Simplify * license * Remove trait * review comments * Error on non-prime discriminant * Error type * Revert "Error type" This reverts commit 28422f9. * test * fix limit * test * clippy * review * Document challenge size * Update test * Remove debug code
- Loading branch information
Showing
22 changed files
with
625 additions
and
544 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use num_bigint::BigInt; | ||
use serde::Deserialize; | ||
use serde::Deserializer; | ||
use serde::Serialize; | ||
use serde::Serializer; | ||
|
||
pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result<BigInt, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
Ok(BigInt::from_signed_bytes_be(&<Vec<u8>>::deserialize( | ||
deserializer, | ||
)?)) | ||
} | ||
|
||
pub(crate) fn serialize<S>(value: &BigInt, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
value.to_signed_bytes_be().serialize(serializer) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use num_bigint::BigInt; | ||
|
||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)] | ||
#[serde(transparent)] | ||
struct TestStruct( | ||
#[serde(serialize_with = "serialize", deserialize_with = "deserialize")] BigInt, | ||
); | ||
|
||
#[test] | ||
fn test_serde() { | ||
let test_values = vec![ | ||
TestStruct(BigInt::from(-1234567890)), | ||
TestStruct(BigInt::from(1234567890)), | ||
TestStruct(BigInt::from(0)), | ||
]; | ||
for value in test_values { | ||
let serialized = bcs::to_bytes(&value).unwrap(); | ||
let deserialized: TestStruct = bcs::from_bytes(&serialized).unwrap(); | ||
assert_eq!(value, deserialized); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.