From 7667960b24e63b23518408337c69d5f36c5dfd94 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Fri, 1 Jul 2022 16:04:26 +0700 Subject: Custom serialization --- crypto/src/math/BigInteger.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'crypto/src/math') diff --git a/crypto/src/math/BigInteger.cs b/crypto/src/math/BigInteger.cs index 98d1fcb1d..50229e2db 100644 --- a/crypto/src/math/BigInteger.cs +++ b/crypto/src/math/BigInteger.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; +using System.Runtime.Serialization; using System.Text; using Org.BouncyCastle.Security; @@ -9,9 +10,7 @@ using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Math { -#if !PORTABLE [Serializable] -#endif public class BigInteger { // The first few odd primes @@ -239,10 +238,22 @@ namespace Org.BouncyCastle.Math private int[] magnitude; // array of ints with [0] being the most significant private int sign; // -1 means -ve; +1 means +ve; 0 means 0; + + [NonSerialized] private int nBits = -1; // cache BitCount() value + [NonSerialized] private int nBitLength = -1; // cache BitLength() value + [NonSerialized] private int mQuote = 0; // -m^(-1) mod b, b = 2^32 (see Montgomery mult.), 0 when uninitialised + [OnDeserialized] + private void OnDeserialized(StreamingContext context) + { + this.nBits = -1; + this.nBitLength = -1; + this.mQuote = 0; + } + private static int GetByteLength( int nBits) { -- cgit 1.4.1