Changeset 197
- Timestamp:
- 3/10/2008 12:26:59 PM (5 years ago)
- File:
-
- 1 edited
-
branches/eraser6/Manager/Method.cs (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Manager/Method.cs
r193 r197 49 49 50 50 /// <summary> 51 /// Disk operation write unit. Chosen such that this value mod 3, 4, 512, 52 /// and 1024 is 0 53 /// </summary> 54 protected const uint DiskOperationUnit = 1536 * 4096 * 2; 55 56 /// <summary> 57 /// Unused space erasure file size. Each of the files used in erasing 58 /// unused space will be of this size. 59 /// </summary> 60 protected const uint FreeSpaceFileUnit = DiskOperationUnit * 36; 61 62 /// <summary> 51 63 /// A simple callback for clients to retrieve progress information from 52 64 /// the erase method. … … 70 82 /// <param name="callback">The progress callback function.</param> 71 83 public abstract void Erase(Stream strm, PRNG prng, OnProgress callback); 84 85 /// <summary> 86 /// Shuffles the passes in the input array, effectively randomizing the 87 /// order or rewrites. 88 /// </summary> 89 /// <param name="passes">The input set of passes.</param> 90 /// <returns>The shuffled set of passes.</returns> 91 protected static Pass[] ShufflePasses(Pass[] passes) 92 { 93 //Make a copy. 94 Pass[] result = new Pass[passes.Length]; 95 passes.CopyTo(result, 0); 96 97 //Randomize. 98 PRNG rand = PRNGManager.GetInstance(Globals.Settings.ActivePRNG); 99 for (int i = 0; i < result.Length; ++i) 100 { 101 int val = rand.Next(result.Length - 1); 102 Pass tmpPass = result[val]; 103 result[val] = result[i]; 104 result[i] = tmpPass; 105 } 106 107 return result; 108 } 109 110 /// <summary> 111 /// Helper function. This function will write random data to the stream 112 /// using the provided PRNG. 113 /// </summary> 114 /// <param name="strm">The buffer to populate with data to write to disk.</param> 115 /// <param name="prng">The PRNG used.</param> 116 protected static void WriteRandom(ref byte[] buffer, object value) 117 { 118 ((PRNG)value).NextBytes(buffer); 119 } 120 121 /// <summary> 122 /// Helper function. This function will write the repeating pattern 123 /// to the stream. 124 /// </summary> 125 /// <param name="strm">The buffer to populate with data to write to disk.</param> 126 /// <param name="value">The byte[] to write.</param> 127 protected static void WriteConstant(ref byte[] buffer, object value) 128 { 129 byte[] pattern = (byte[])value; 130 for (int i = 0; i < buffer.Length; ++i) 131 buffer[i] = pattern[i % pattern.Length]; 132 } 133 134 /// <summary> 135 /// The prototype of a pass. 136 /// </summary> 137 /// <param name="strm">The buffer to populate with data to write to disk.</param> 138 /// <param name="opaque">An opaque value, depending on the type of callback.</param> 139 protected delegate void PassFunction(ref byte[] buffer, object opaque); 140 141 /// <summary> 142 /// A pass object. This object holds both the pass function, as well as the 143 /// data used for the pass (random, byte, or triplet) 144 /// </summary> 145 protected struct Pass 146 { 147 public override string ToString() 148 { 149 return OpaqueValue == null ? "Random" : OpaqueValue.ToString(); 150 } 151 152 /// <summary> 153 /// Constructor. 154 /// </summary> 155 /// <param name="function">The delegate to the function.</param> 156 /// <param name="opaqueValue">The opaque value passed to the function.</param> 157 public Pass(PassFunction function, object opaqueValue) 158 { 159 Function = function; 160 OpaqueValue = opaqueValue; 161 } 162 163 /// <summary> 164 /// Executes the pass. 165 /// </summary> 166 /// <param name="buffer">The buffer to populate with the data to write.</param> 167 /// <param name="prng">The PRNG used for random passes.</param> 168 public void Execute(ref byte[] buffer, PRNG prng) 169 { 170 Function(ref buffer, OpaqueValue == null ? prng : OpaqueValue); 171 } 172 173 PassFunction Function; 174 object OpaqueValue; 175 } 72 176 } 73 177 … … 137 241 return Globals.ErasureMethodManager.methods[guid]; 138 242 } 139 catch (KeyNotFoundException e)243 catch (KeyNotFoundException) 140 244 { 141 245 throw new FatalException("PRNG not found: " + guid.ToString());
Note: See TracChangeset
for help on using the changeset viewer.
