Changeset 2443


Ignore:
Timestamp:
3/12/2012 3:53:11 AM (3 years ago)
Author:
lowjoel
Message:

Made all the extension points in Eraser.Plugins to be interfaces, to be true to the need for the Plugins assembly. Move all the implementation to Eraser.DefaultPlugins? (will be in a separate commit since basically the entire library needs to be rewritten.)

Location:
branches/eraser6/pluginsRewrite
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/pluginsRewrite/Eraser.Manager/EntropyPoller.cs

    r2363 r2443  
    8383                st.Start(); 
    8484                lock (EntropySources) 
    85                     foreach (EntropySource src in EntropySources) 
     85                    foreach (IEntropySource src in EntropySources) 
    8686                    { 
    8787                        byte[] entropy = src.GetEntropy(); 
     
    112112        /// </summary> 
    113113        /// <param name="source">The EntropySource object to add.</param> 
    114         public void AddEntropySource(EntropySource source) 
     114        public void AddEntropySource(IEntropySource source) 
    115115        { 
    116116            lock (EntropySources) 
     
    324324        /// The list of entropy sources registered with the Poller. 
    325325        /// </summary> 
    326         private List<EntropySource> EntropySources = new List<EntropySource>(); 
     326        private List<IEntropySource> EntropySources = new List<IEntropySource>(); 
    327327    } 
    328328} 
  • branches/eraser6/pluginsRewrite/Eraser.Manager/Task.cs

    r2440 r2443  
    126126                    //Simpler case, small set of data. 
    127127                    foreach (IErasureTarget tgt in Targets) 
    128                         result += S._("{0}, ", tgt.UIText); 
     128                        result += S._("{0}, ", tgt); 
    129129 
    130130                    return result.Remove(result.Length - 2); 
     
    133133                { 
    134134                    //Ok, we've quite a few entries, get the first, the mid and the end. 
    135                     result = S._("{0}, ", Targets[0].UIText); 
    136                     result += S._("{0}, ", Targets[Targets.Count / 2].UIText); 
    137                     result += Targets[Targets.Count - 1].UIText; 
     135                    result = S._("{0}, ", Targets[0]); 
     136                    result += S._("{0}, ", Targets[Targets.Count / 2]); 
     137                    result += Targets[Targets.Count - 1]; 
    138138 
    139139                    return S._("{0} and {1} other targets", result, Targets.Count - 3); 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/Eraser.Plugins.csproj

    r2440 r2443  
    5858    <Compile Include="ExtensionPoints\IErasureTarget.cs" /> 
    5959    <Compile Include="ExtensionPoints\IFileSystem.cs" /> 
    60     <Compile Include="ExtensionPoints\Prng.cs" /> 
     60    <Compile Include="ExtensionPoints\IPrng.cs" /> 
    6161    <Compile Include="IConfigurer.cs" /> 
    6262    <Compile Include="IPlugin.cs" /> 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/ExtensionPoints/IEntropySource.cs

    r2439 r2443  
    3535    { 
    3636        /// <summary> 
    37         /// Constructor. 
    38         /// </summary> 
    39         protected EntropySource() 
    40         { 
    41         } 
    42  
    43         /// <summary> 
    4437        /// The name of the entropy source 
    4538        /// </summary> 
    46         public abstract string Name 
    47         { 
    48             get; 
    49         } 
    50  
    51         /// <summary> 
    52         /// The guid representing this entropy source 
    53         /// </summary> 
    54         public abstract Guid Guid 
     39        string Name 
    5540        { 
    5641            get; 
     
    6247        /// </summary> 
    6348        /// <returns>A byte array containing the entropy.</returns> 
    64         public abstract byte[] GetPrimer(); 
     49        byte[] GetPrimer(); 
    6550 
    6651        /// <summary> 
     
    6954        /// </summary> 
    7055        /// <returns></returns> 
    71         public abstract byte[] GetSlowEntropy(); 
     56        byte[] GetSlowEntropy(); 
    7257 
    7358        /// <summary> 
     
    7661        /// </summary> 
    7762        /// <returns></returns> 
    78         public abstract byte[] GetFastEntropy(); 
     63        byte[] GetFastEntropy(); 
    7964 
    8065        /// <summary> 
     
    8267        /// </summary> 
    8368        /// <returns>A byte array containing the entropy, both slow rate and fast rate.</returns> 
    84         public abstract byte[] GetEntropy(); 
    85  
    86         /// <summary> 
    87         /// Converts value types into a byte array. This is a helper function to allow 
    88         /// inherited classes to convert value types into byte arrays which can be 
    89         /// returned to the EntropyPoller class. 
    90         /// </summary> 
    91         /// <typeparam name="T">Any value type</typeparam> 
    92         /// <param name="entropy">A value which will be XORed with pool contents.</param> 
    93         protected static byte[] StructToBuffer<T>(T entropy) where T : struct 
    94         { 
    95             int sizeofObject = Marshal.SizeOf(entropy); 
    96             IntPtr memory = Marshal.AllocHGlobal(sizeofObject); 
    97             try 
    98             { 
    99                 Marshal.StructureToPtr(entropy, memory, false); 
    100                 byte[] dest = new byte[sizeofObject]; 
    101  
    102                 //Copy the memory 
    103                 Marshal.Copy(memory, dest, 0, sizeofObject); 
    104                 return dest; 
    105             } 
    106             finally 
    107             { 
    108                 Marshal.FreeHGlobal(memory); 
    109             } 
    110         } 
     69        byte[] GetEntropy(); 
    11170    } 
    11271} 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/ExtensionPoints/IErasureMethod.cs

    r2439 r2443  
    3535    /// streams, not unused drive space. 
    3636    /// </summary> 
    37     public abstract class IErasureMethod : IRegisterable 
     37    public interface IErasureMethod : IRegisterable 
    3838    { 
    39         public override string ToString() 
    40         { 
    41             if (Passes == 0) 
    42                 return Name; 
    43             return Passes == 1 ? S._("{0} (1 pass)", Name) : 
    44                 S._("{0} ({1} passes)", Name, Passes); 
    45         } 
     39        /// <summary> 
     40        /// Returns a string that represents the current IErasureMethod. The suggested 
     41        /// template is {name} ({pass count} passes) 
     42        /// </summary> 
     43        /// <returns>The string that represents the current IErasureMethod.</returns> 
     44        string ToString(); 
    4645 
    4746        /// <summary> 
    4847        /// The name of this erase pass, used for display in the UI 
    4948        /// </summary> 
    50         public abstract string Name 
     49        string Name 
    5150        { 
    5251            get; 
     
    5655        /// The number of erase passes for this erasure method. 
    5756        /// </summary> 
    58         public abstract int Passes 
    59         { 
    60             get; 
    61         } 
    62  
    63         /// <summary> 
    64         /// The GUID for this erasure method. 
    65         /// </summary> 
    66         public abstract Guid Guid 
     57        int Passes 
    6758        { 
    6859            get; 
     
    8475        /// are already provided. However some exceptional cases may take a 
    8576        /// long time if the data set is large.</remarks> 
    86         public abstract long CalculateEraseDataSize(ICollection<StreamInfo> paths, long targetSize); 
     77        long CalculateEraseDataSize(ICollection<StreamInfo> paths, long targetSize); 
    8778 
    8879        /// <summary> 
     
    10091        /// <param name="prng">The PRNG source for random data.</param> 
    10192        /// <param name="callback">The progress callback function.</param> 
    102         public abstract void Erase(Stream stream, long erasureLength, IPrng prng, 
     93        void Erase(Stream stream, long erasureLength, IPrng prng, 
    10394            ErasureMethodProgressFunction callback); 
    104  
    105         /// <summary> 
    106         /// Disk operation write unit. Chosen such that this value mod 3, 4, 512, 
    107         /// and 1024 is 0 
    108         /// </summary> 
    109         public const int DiskOperationUnit = 1536 * 4096; 
    110  
    111         /// <summary> 
    112         /// Unused space erasure file size. Each of the files used in erasing 
    113         /// unused space will be of this size. 
    114         /// </summary> 
    115         public const int FreeSpaceFileUnit = DiskOperationUnit * 36; 
    116  
    117         /// <summary> 
    118         /// Shuffles the passes in the input array, effectively randomizing the 
    119         /// order or rewrites. 
    120         /// </summary> 
    121         /// <param name="passes">The input set of passes.</param> 
    122         /// <returns>The shuffled set of passes.</returns> 
    123         protected static ErasureMethodPass[] ShufflePasses(ErasureMethodPass[] passes) 
    124         { 
    125             //Make a copy. 
    126             ErasureMethodPass[] result = new ErasureMethodPass[passes.Length]; 
    127             passes.CopyTo(result, 0); 
    128  
    129             //Randomize. 
    130             IPrng rand = Host.Instance.Prngs.ActivePrng; 
    131             for (int i = 0; i < result.Length; ++i) 
    132             { 
    133                 int val = rand.Next(result.Length - 1); 
    134                 ErasureMethodPass tmpPass = result[val]; 
    135                 result[val] = result[i]; 
    136                 result[i] = tmpPass; 
    137             } 
    138  
    139             return result; 
    140         } 
    141  
    142         /// <summary> 
    143         /// Helper function. This function will write random data to the stream 
    144         /// using the provided PRNG. 
    145         /// </summary> 
    146         /// <param name="strm">The buffer to populate with data to write to disk.</param> 
    147         /// <param name="prng">The PRNG used.</param> 
    148         public static void WriteRandom(byte[] buffer, object value) 
    149         { 
    150             ((IPrng)value).NextBytes(buffer); 
    151         } 
    152  
    153         /// <summary> 
    154         /// Helper function. This function will write the repeating pass constant. 
    155         /// to the provided buffer. 
    156         /// </summary> 
    157         /// <param name="strm">The buffer to populate with data to write to disk.</param> 
    158         /// <param name="value">The byte[] to write.</param> 
    159         public static void WriteConstant(byte[] buffer, object value) 
    160         { 
    161             byte[] constant = (byte[])value; 
    162             for (int i = 0; i < buffer.Length; ++i) 
    163                 buffer[i] = constant[i % constant.Length]; 
    164         } 
    165  
    166         /// A simple callback for clients to retrieve progress information from 
    167         /// the erase method. 
    168         /// </summary> 
    169         /// <param name="lastWritten">The amount of data written to the stream since 
    170         /// the last call to the delegate.</param> 
    171         /// <param name="totalData">The total amount of data that must be written to 
    172         /// complete the erasure.</param> 
    173         /// <param name="currentPass">The current pass number. The total number 
    174         /// of passes can be found from the Passes property.</param> 
    175         public delegate void ErasureMethodProgressFunction(long lastWritten, long totalData, 
    176             int currentPass); 
    17795    } 
    17896 
    179     /// <summary> 
     97    /// A simple callback for clients to retrieve progress information from 
     98    /// the erase method. 
     99    /// </summary> 
     100    /// <param name="lastWritten">The amount of data written to the stream since 
     101    /// the last call to the delegate.</param> 
     102    /// <param name="totalData">The total amount of data that must be written to 
     103    /// complete the erasure.</param> 
     104    /// <param name="currentPass">The current pass number. The total number 
     105    /// of passes can be found from the Passes property.</param> 
     106    public delegate void ErasureMethodProgressFunction(long lastWritten, 
     107        long totalData, int currentPass); 
     108 
    180109    /// <summary> 
    181110    /// This class adds functionality to the ErasureMethod class to erase 
    182111    /// unused drive space. 
    183112    /// </summary> 
    184     public abstract class UnusedSpaceErasureMethod : IErasureMethod 
     113    public interface IUnusedSpaceErasureMethod : IErasureMethod 
    185114    { 
    186115        /// <summary> 
     
    197126        /// <param name="prng">The PRNG source for random data.</param> 
    198127        /// <param name="callback">The progress callback function.</param> 
    199         public virtual void EraseUnusedSpace(Stream stream, IPrng prng, ErasureMethodProgressFunction callback) 
    200         { 
    201             Erase(stream, long.MaxValue, prng, callback); 
    202         } 
    203     } 
    204  
    205     /// <summary> 
    206     /// Pass-based erasure method. This subclass of erasure methods follow a fixed 
    207     /// pattern (constant or random data) for every pass, although the order of 
    208     /// passes can be randomized. This is to simplify definitions of classes in 
    209     /// plugins. 
    210     ///  
    211     /// Since instances of this class apply data by passes, they can by default 
    212     /// erase unused drive space as well. 
    213     /// </summary> 
    214     public abstract class PassBasedErasureMethod : UnusedSpaceErasureMethod 
    215     { 
    216         public override int Passes 
    217         { 
    218             get { return PassesSet.Length; } 
    219         } 
    220  
    221         /// <summary> 
    222         /// Whether the passes should be randomized before running them in random 
    223         /// order. 
    224         /// </summary> 
    225         protected abstract bool RandomizePasses 
    226         { 
    227             get; 
    228         } 
    229  
    230         /// <summary> 
    231         /// The set of Pass objects describing the passes in this erasure method. 
    232         /// </summary> 
    233         protected abstract ErasureMethodPass[] PassesSet 
    234         { 
    235             get; 
    236         } 
    237  
    238         public override long CalculateEraseDataSize(ICollection<StreamInfo> paths, long targetSize) 
    239         { 
    240             //Simple. Amount of data multiplied by passes. 
    241             return targetSize * Passes; 
    242         } 
    243  
    244         public override void Erase(Stream stream, long erasureLength, IPrng prng, 
    245             ErasureMethodProgressFunction callback) 
    246         { 
    247             //Randomize the order of the passes 
    248             ErasureMethodPass[] randomizedPasses = PassesSet; 
    249             if (RandomizePasses) 
    250                 randomizedPasses = ShufflePasses(randomizedPasses); 
    251  
    252             //Remember the starting position of the stream. 
    253             long strmStart = stream.Position; 
    254             long strmLength = Math.Min(stream.Length - strmStart, erasureLength); 
    255             long totalData = CalculateEraseDataSize(null, strmLength); 
    256  
    257             //Allocate memory for a buffer holding data for the pass. 
    258             byte[] buffer = new byte[Math.Min(DiskOperationUnit, strmLength)]; 
    259  
    260             //Run every pass! 
    261             for (int pass = 0; pass < Passes; ++pass) 
    262             { 
    263                 //Do a progress callback first. 
    264                 if (callback != null) 
    265                     callback(0, totalData, pass + 1); 
    266  
    267                 //Start from the beginning again 
    268                 stream.Seek(strmStart, SeekOrigin.Begin); 
    269  
    270                 //Write the buffer to disk. 
    271                 long toWrite = strmLength; 
    272                 int dataStopped = buffer.Length; 
    273                 while (toWrite > 0) 
    274                 { 
    275                     //Calculate how much of the buffer to write to disk. 
    276                     int amount = (int)Math.Min(toWrite, buffer.Length - dataStopped); 
    277  
    278                     //If we have no data left, get more! 
    279                     if (amount == 0) 
    280                     { 
    281                         randomizedPasses[pass].Execute(buffer, prng); 
    282                         dataStopped = 0; 
    283                         continue; 
    284                     } 
    285  
    286                     //Write the data. 
    287                     stream.Write(buffer, dataStopped, amount); 
    288                     stream.Flush(); 
    289                     toWrite -= amount; 
    290  
    291                     //Do a progress callback. 
    292                     if (callback != null) 
    293                         callback(amount, totalData, pass + 1); 
    294                 } 
    295             } 
    296         } 
    297     } 
    298  
    299     /// <summary> 
    300     /// A pass object. This object holds both the pass function, as well as the 
    301     /// data used for the pass (random, byte, or triplet) 
    302     /// </summary> 
    303     public class ErasureMethodPass 
    304     { 
    305         public override string ToString() 
    306         { 
    307             return OpaqueValue == null ? S._("Random") : OpaqueValue.ToString(); 
    308         } 
    309  
    310         /// <summary> 
    311         /// Constructor. 
    312         /// </summary> 
    313         /// <param name="function">The delegate to the function.</param> 
    314         /// <param name="opaqueValue">The opaque value passed to the function.</param> 
    315         public ErasureMethodPass(ErasureMethodPassFunction function, object opaqueValue) 
    316         { 
    317             Function = function; 
    318             OpaqueValue = opaqueValue; 
    319         } 
    320  
    321         /// <summary> 
    322         /// Executes the pass. 
    323         /// </summary> 
    324         /// <param name="buffer">The buffer to populate with the data to write.</param> 
    325         /// <param name="prng">The PRNG used for random passes.</param> 
    326         public void Execute(byte[] buffer, IPrng prng) 
    327         { 
    328             Function(buffer, OpaqueValue == null ? prng : OpaqueValue); 
    329         } 
    330  
    331         /// <summary> 
    332         /// The function to execute for this pass. 
    333         /// </summary> 
    334         public ErasureMethodPassFunction Function { get; set; } 
    335  
    336         /// <summary> 
    337         /// The value to be passed to the executing function. 
    338         /// </summary> 
    339         public object OpaqueValue { get; set; } 
    340  
    341         /// <summary> 
    342         /// The prototype of a pass. 
    343         /// </summary> 
    344         /// <param name="strm">The buffer to populate with data to write to disk.</param> 
    345         /// <param name="opaque">An opaque value, depending on the type of callback.</param> 
    346         public delegate void ErasureMethodPassFunction(byte[] buffer, object opaque); 
     128        void EraseUnusedSpace(Stream stream, IPrng prng, ErasureMethodProgressFunction callback); 
    347129    } 
    348130} 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/ExtensionPoints/IErasureTarget.cs

    r2439 r2443  
    3636    /// Represents a generic target of erasure 
    3737    /// </summary> 
    38     [Serializable] 
    39     public abstract class IErasureTarget : ISerializable, IRegisterable 
     38    public interface IErasureTarget : ISerializable, IRegisterable 
    4039    { 
    41         #region Serialization code 
    42         protected IErasureTarget(SerializationInfo info, StreamingContext context) 
    43         { 
    44             Guid methodGuid = (Guid)info.GetValue("Method", typeof(Guid)); 
    45             if (methodGuid == Guid.Empty) 
    46                 Method = ErasureMethodRegistrar.Default; 
    47             else 
    48                 Method = Host.Instance.ErasureMethods[methodGuid]; 
    49         } 
    50  
    51         [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)] 
    52         public virtual void GetObjectData(SerializationInfo info, StreamingContext context) 
    53         { 
    54             info.AddValue("Method", Method.Guid); 
    55         } 
    56         #endregion 
    57  
    58         #region IRegisterable Members 
    59  
    60         public abstract Guid Guid 
    61         { 
    62             get; 
    63         } 
    64  
    65         #endregion 
    66  
    6740        /// <summary> 
    68         /// Constructor. 
     41        /// Retrieves the text to display representing this target. 
    6942        /// </summary> 
    70         protected IErasureTarget() 
    71         { 
    72             Method = ErasureMethodRegistrar.Default; 
    73         } 
     43        string ToString(); 
    7444 
    7545        /// <summary> 
    7646        /// The name of the type of the Erasure target. 
    7747        /// </summary> 
    78         public abstract string Name 
     48        string Name 
    7949        { 
    8050            get; 
     
    8454        /// The method used for erasing the file. 
    8555        /// </summary> 
    86         public IErasureMethod Method 
     56        IErasureMethod Method 
    8757        { 
    88             get 
    89             { 
    90                 return method; 
    91             } 
    92             set 
    93             { 
    94                 if (!SupportsMethod(value)) 
    95                     throw new ArgumentException(S._("The selected erasure method is not " + 
    96                         "supported for this erasure target.")); 
    97                 method = value; 
    98             } 
    99         } 
    100  
    101         /// <summary> 
    102         /// Gets the effective erasure method for the current target (i.e., returns 
    103         /// the correct erasure method for cases where the <see cref="Method"/> 
    104         /// property is <see cref="ErasureMethodRegistrar.Default"/> 
    105         /// </summary> 
    106         /// <returns>The Erasure method which the target should be erased with. 
    107         /// This function will never return <see cref="ErasureMethodRegistrar.Default"/></returns> 
    108         public virtual IErasureMethod EffectiveMethod 
    109         { 
    110             get 
    111             { 
    112                 if (Method != ErasureMethodRegistrar.Default) 
    113                     return Method; 
    114  
    115                 throw new InvalidOperationException("The effective method of the erasure " + 
    116                     "target cannot be ErasureMethodRegistrar.Default"); 
    117             } 
     58            get; 
     59            set; 
    11860        } 
    11961 
     
    12466        /// <param name="method">The erasure method to check.</param> 
    12567        /// <returns>True if the erasure method is supported, false otherwise.</returns> 
    126         public virtual bool SupportsMethod(IErasureMethod method) 
    127         { 
    128             return true; 
    129         } 
    130  
    131         /// <summary> 
    132         /// Retrieves the text to display representing this target. 
    133         /// </summary> 
    134         public abstract string UIText 
    135         { 
    136             get; 
    137         } 
    138  
    139         /// <summary> 
    140         /// The Progress Changed event handler of the owning task. 
    141         /// </summary> 
    142         protected internal Action<IErasureTarget, ProgressChangedEventArgs> OnProgressChanged 
    143         { 
    144             get; 
    145             internal set; 
    146         } 
     68        bool SupportsMethod(IErasureMethod method); 
    14769 
    14870        /// <summary> 
     
    15375        /// function, and settings for this task will be according to the returned 
    15476        /// control.</remarks> 
    155         public abstract IErasureTargetConfigurer Configurer 
     77        IErasureTargetConfigurer Configurer 
    15678        { 
    15779            get; 
     
    16183        /// Executes the given target. 
    16284        /// </summary> 
    163         public abstract void Execute(); 
    164  
    165         /// <summary> 
    166         /// The backing variable for the <see cref="Method"/> property. 
    167         /// </summary> 
    168         private IErasureMethod method; 
     85        void Execute(); 
    16986    } 
    17087 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/ExtensionPoints/IFileSystem.cs

    r2439 r2443  
    3434    /// Provides functions to handle erasures specfic to file systems. 
    3535    /// </summary> 
    36     public abstract class IFileSystem : IRegisterable 
     36    public interface IFileSystem : IRegisterable 
    3737    { 
    38         /// <summary> 
    39         /// Generates a random file name with the given length. 
    40         /// </summary> 
    41         /// <remarks>The generated file name is guaranteed not to exist.</remarks> 
    42         /// <param name="info">The directory to generate the file name in. This 
    43         /// parameter can be null to indicate merely a random file name</param> 
    44         /// <param name="length">The length of the file name to generate.</param> 
    45         /// <returns>A full path to a file containing random file name.</returns> 
    46         public static string GenerateRandomFileName(DirectoryInfo info, int length) 
    47         { 
    48             //Get the PRNG we are going to use 
    49             IPrng prng = Host.Instance.Prngs.ActivePrng; 
    50  
    51             //Initialsie the base name, if any. 
    52             string resultPrefix = info == null ? string.Empty : info.FullName + 
    53                 Path.DirectorySeparatorChar; 
    54  
    55             //Variables to store the intermediates. 
    56             byte[] resultAry = new byte[length]; 
    57             string result = string.Empty; 
    58             List<string> prohibitedFileNames = new List<string>(new string[] { 
    59                 "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", 
    60                 "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", 
    61                 "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" 
    62             }); 
    63  
    64             do 
    65             { 
    66                 prng.NextBytes(resultAry); 
    67  
    68                 //Validate the name 
    69                 string validFileNameChars = "0123456789abcdefghijklmnopqrstuvwxyz" + 
    70                     "ABCDEFGHIJKLMNOPQRSTUVWXYZ _+=-()[]{}',`~!"; 
    71                 for (int j = 0, k = resultAry.Length; j < k; ++j) 
    72                 { 
    73                     resultAry[j] = (byte)validFileNameChars[ 
    74                         (int)resultAry[j] % validFileNameChars.Length]; 
    75  
    76                     if (j == 0 || j == k - 1) 
    77                         //The first or last character cannot be whitespace 
    78                         while (Char.IsWhiteSpace((char)resultAry[j])) 
    79                             resultAry[j] = (byte)validFileNameChars[ 
    80                                 (int)resultAry[j] % validFileNameChars.Length]; 
    81                 } 
    82  
    83                 result = Encoding.UTF8.GetString(resultAry); 
    84             } 
    85             while (info != null && 
    86                 prohibitedFileNames.IndexOf(Path.GetFileNameWithoutExtension(result)) != -1 || 
    87                 (Directory.Exists(resultPrefix + result) || File.Exists(resultPrefix + result))); 
    88             return resultPrefix + result; 
    89         } 
    90  
    91         /// <summary> 
    92         /// Gets a random file from within the provided directory. 
    93         /// </summary> 
    94         /// <param name="info">The directory to get a random file name from.</param> 
    95         /// <returns>A string containing the full path to the file.</returns> 
    96         public static string GetRandomFile(DirectoryInfo info) 
    97         { 
    98             //First retrieve the list of files and folders in the provided directory. 
    99             FileSystemInfo[] entries = null; 
    100             try 
    101             { 
    102                 entries = info.GetFileSystemInfos(); 
    103             } 
    104             catch (DirectoryNotFoundException) 
    105             { 
    106                 return string.Empty; 
    107             } 
    108             if (entries.Length == 0) 
    109                 return string.Empty; 
    110  
    111             //Find a random entry. 
    112             IPrng prng = Host.Instance.Prngs.ActivePrng; 
    113             string result = string.Empty; 
    114             while (result.Length == 0) 
    115             { 
    116                 int index = prng.Next(entries.Length - 1); 
    117                 if (entries[index] is DirectoryInfo) 
    118                     result = GetRandomFile((DirectoryInfo)entries[index]); 
    119                 else 
    120                     result = ((FileInfo)entries[index]).FullName; 
    121             } 
    122  
    123             return result; 
    124         } 
    125  
    126         /// <summary> 
    127         /// The Guid of the current filesystem. 
    128         /// </summary> 
    129         public abstract Guid Guid 
    130         { 
    131             get; 
    132         } 
    133  
    13438        /// <summary> 
    13539        /// The name of the current filesystem. 
    13640        /// </summary> 
    137         public abstract string Name 
     41        string Name 
    13842        { 
    13943            get; 
     
    14549        /// </summary> 
    14650        /// <param name="info">The file to reset times.</param> 
    147         public abstract void ResetFileTimes(FileSystemInfo info); 
     51        void ResetFileTimes(FileSystemInfo info); 
    14852 
    14953        /// <summary> 
     
    15357        /// </summary> 
    15458        /// <param name="info">The file to delete.</param> 
    155         public abstract void DeleteFile(FileInfo info); 
     59        void DeleteFile(FileInfo info); 
    15660 
    15761        /// <summary> 
     
    16367        /// <param name="recursive">True if the folder and all its subfolders and 
    16468        /// files to be securely deleted.</param> 
    165         public abstract void DeleteFolder(DirectoryInfo info, bool recursive); 
    166  
    167         /// <seealso cref="DeleteFolder"/> 
    168         /// <param name="info">The folder to delete.</param> 
    169         public void DeleteFolder(DirectoryInfo info) 
    170         { 
    171             DeleteFolder(info, true); 
    172         } 
    173  
    174         /// <summary> 
    175         /// The function prototype for cluster tip search progress callbacks. This is 
    176         /// called when the cluster tips are being searched. 
    177         /// </summary> 
    178         /// <param name="currentPath">The directory being searched</param> 
    179         public delegate void ClusterTipsSearchProgress(string currentPath); 
    180  
    181         /// <summary> 
    182         /// The function prototype for cluster tip erasure callbacks. This is called when 
    183         /// the cluster tips are being erased. 
    184         /// </summary> 
    185         /// <param name="currentFile">The current file index being erased.</param> 
    186         /// <param name="totalFiles">The total number of files to be erased.</param> 
    187         /// <param name="currentFilePath">The path to the current file being erased.</param> 
    188         public delegate void ClusterTipsEraseProgress(int currentFile, int totalFiles, 
    189             string currentFilePath); 
    190  
    191         /// <summary> 
    192         /// The prototype of callbacks handling the file system table erase progress. 
    193         /// </summary> 
    194         /// <param name="currentFile">The current file being erased.</param> 
    195         /// <param name="totalFiles">The estimated number of files that must be 
    196         /// erased.</param> 
    197         public delegate void FileSystemEntriesEraseProgress(int currentFile, int totalFiles); 
     69        void DeleteFolder(DirectoryInfo info, bool recursive); 
    19870 
    19971        /// <summary> 
     
    20577        /// <param name="searchCallback">The callback function for search progress.</param> 
    20678        /// <param name="eraseCallback">The callback function for erasure progress.</param> 
    207         public abstract void EraseClusterTips(VolumeInfo info, IErasureMethod method, 
     79        void EraseClusterTips(VolumeInfo info, IErasureMethod method, 
    20880            ClusterTipsSearchProgress searchCallback, ClusterTipsEraseProgress eraseCallback); 
    20981 
     
    21991        /// to store temporary files used for resident file cleaning.</param> 
    22092        /// <param name="method">The method used to erase the files.</param> 
    221         public abstract void EraseOldFileSystemResidentFiles(VolumeInfo volume, 
    222             DirectoryInfo tempDirectory, IErasureMethod method, 
    223             FileSystemEntriesEraseProgress callback); 
     93        void EraseOldFileSystemResidentFiles(VolumeInfo volume, DirectoryInfo tempDirectory, 
     94            IErasureMethod method, FileSystemEntriesEraseProgress callback); 
    22495 
    22596        /// <summary> 
     
    234105        /// <param name="callback">The callback function to handle the progress 
    235106        /// of the file system entry erasure.</param> 
    236         public abstract void EraseDirectoryStructures(VolumeInfo info, 
    237             FileSystemEntriesEraseProgress callback); 
     107        void EraseDirectoryStructures(VolumeInfo info, FileSystemEntriesEraseProgress callback); 
    238108 
    239109        /// <summary> 
     
    241111        /// </summary> 
    242112        /// <param name="info"></param> 
    243         public abstract void EraseFileSystemObject(StreamInfo info, IErasureMethod method, 
    244             IErasureMethod.ErasureMethodProgressFunction callback); 
     113        void EraseFileSystemObject(StreamInfo info, IErasureMethod method, 
     114            ErasureMethodProgressFunction callback); 
    245115 
    246116        //TODO: This is supposed to be in VolumeInfo! 
     
    251121        /// <param name="streamInfo">The Stream to get the area for.</param> 
    252122        /// <returns>The area of the file.</returns> 
    253         public abstract long GetFileArea(StreamInfo filePath); 
     123        long GetFileArea(StreamInfo filePath); 
     124    } 
    254125 
    255         /// <summary> 
    256         /// The number of times file names are renamed to erase the file name from 
    257         /// the file system table. 
    258         /// </summary> 
    259         public const int FileNameErasePasses = 7; 
     126    /// <summary> 
     127    /// The function prototype for cluster tip search progress callbacks. This is 
     128    /// called when the cluster tips are being searched. 
     129    /// </summary> 
     130    /// <param name="currentPath">The directory being searched</param> 
     131    public delegate void ClusterTipsSearchProgress(string currentPath); 
    260132 
    261         /// <summary> 
    262         /// The maximum number of times Eraser tries to erase a file/folder before 
    263         /// it gives up. 
    264         /// </summary> 
    265         public const int FileNameEraseTries = 50; 
    266     } 
     133    /// <summary> 
     134    /// The function prototype for cluster tip erasure callbacks. This is called when 
     135    /// the cluster tips are being erased. 
     136    /// </summary> 
     137    /// <param name="currentFile">The current file index being erased.</param> 
     138    /// <param name="totalFiles">The total number of files to be erased.</param> 
     139    /// <param name="currentFilePath">The path to the current file being erased.</param> 
     140    public delegate void ClusterTipsEraseProgress(int currentFile, int totalFiles, 
     141        string currentFilePath); 
     142 
     143    /// <summary> 
     144    /// The prototype of callbacks handling the file system table erase progress. 
     145    /// </summary> 
     146    /// <param name="currentFile">The current file being erased.</param> 
     147    /// <param name="totalFiles">The estimated number of files that must be 
     148    /// erased.</param> 
     149    public delegate void FileSystemEntriesEraseProgress(int currentFile, int totalFiles); 
    267150} 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/ExtensionPoints/IPrng.cs

    r2439 r2443  
    3131    /// random data erase passes. 
    3232    /// </summary> 
    33     public abstract class IPrng : IRegisterable 
     33    public interface IPrng : IRegisterable 
    3434    { 
    35         public override string ToString() 
    36         { 
    37             return Name; 
    38         } 
     35        /// <summary> 
     36        /// Returns a string that represents the current IPrng. The suggsted return 
     37        /// value is the Name of the IPrng. 
     38        /// </summary> 
     39        /// <returns>The string that represents the current IPrng.</returns> 
     40        string ToString(); 
    3941 
    4042        /// <summary> 
    4143        /// The name of this erase pass, used for display in the UI 
    4244        /// </summary> 
    43         public abstract string Name 
    44         { 
    45             get; 
    46         } 
    47  
    48         /// <summary> 
    49         /// The GUID for this PRNG. 
    50         /// </summary> 
    51         public abstract Guid Guid 
     45        string Name 
    5246        { 
    5347            get; 
     
    6256        /// <param name="seed">An arbitrary length of information that will be 
    6357        /// used to reseed the PRNG</param> 
    64         protected internal abstract void Reseed(byte[] seed); 
     58        void Reseed(byte[] seed); 
    6559 
    6660        #region Random members 
     
    7468        /// includes zero but not maxValue. However, if maxValue equals zero, 
    7569        /// maxValue is returned.</returns> 
    76         public int Next(int maxValue) 
    77         { 
    78             if (maxValue == 0) 
    79                 return 0; 
    80             return Next() % maxValue; 
    81         } 
     70        int Next(int maxValue); 
    8271 
    8372        /// <summary> 
     
    9180        /// less than maxValue; that is, the range of return values includes minValue 
    9281        /// but not maxValue. If minValue equals maxValue, minValue is returned.</returns> 
    93         public int Next(int minValue, int maxValue) 
    94         { 
    95             if (minValue > maxValue) 
    96                 throw new ArgumentOutOfRangeException("minValue", minValue, 
    97                     "minValue is greater than maxValue"); 
    98             else if (minValue == maxValue) 
    99                 return minValue; 
    100             return (Next() % (maxValue - minValue)) + minValue; 
    101         } 
     82        int Next(int minValue, int maxValue); 
    10283 
    10384        /// <summary> 
     
    10687        /// <returns>A 32-bit signed integer greater than or equal to zero and less 
    10788        /// than System.Int32.MaxValue.</returns> 
    108         public int Next() 
    109         { 
    110             //Get the random-valued bytes to fill the int. 
    111             byte[] rand = new byte[sizeof(int)]; 
    112             NextBytes(rand); 
     89        int Next(); 
    11390 
    114             //Then return the integral representation of the buffer. 
    115             return Math.Abs(BitConverter.ToInt32(rand, 0)); 
    116         } 
     91        /// <summary> 
     92        /// Returns a random number between 0.0 and 1.0. 
     93        /// </summary> 
     94        /// <returns>A double-precision floating point number greater than or equal to 0.0, 
     95        /// and less than 1.0.</returns> 
     96        double NextDouble(); 
    11797 
    11898        /// <summary> 
     
    120100        /// </summary> 
    121101        /// <param name="buffer">An array of bytes to contain random numbers.</param> 
    122         public abstract void NextBytes(byte[] buffer); 
     102        void NextBytes(byte[] buffer); 
    123103        #endregion 
    124104    } 
    125  
    126105} 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/Registrars/EntropySourceRegistrar.cs

    r2357 r2443  
    3333    /// available. Plugins could register their entropy sources via this class. 
    3434    /// </summary> 
    35     public class EntropySourceRegistrar : Registrar<EntropySource> 
     35    public class EntropySourceRegistrar : Registrar<IEntropySource> 
    3636    { 
    3737    }; 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/Strings.en.resx

    r2361 r2443  
    133133    <value>The file system on the drive {0} is not supported.</value> 
    134134  </data> 
    135   <data name="{0} (1 pass)" xml:space="preserve"> 
    136     <value>{0} (1 pass)</value> 
    137   </data> 
    138   <data name="{0} ({1} passes)" xml:space="preserve"> 
    139     <value>{0} ({1} passes)</value> 
    140   </data> 
    141   <data name="Random" xml:space="preserve"> 
    142     <value>Random</value> 
    143   </data> 
    144   <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve"> 
    145     <value>The selected erasure method is not supported for this erasure target.</value> 
    146   </data> 
    147135</root> 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/Strings.it.resx

    r2361 r2443  
    133133    <value>(Untranslated)</value> 
    134134  </data> 
    135   <data name="{0} (1 pass)" xml:space="preserve"> 
    136     <value>(Untranslated)</value> 
    137   </data> 
    138   <data name="{0} ({1} passes)" xml:space="preserve"> 
    139     <value>(Untranslated)</value> 
    140   </data> 
    141   <data name="Random" xml:space="preserve"> 
    142     <value>(Untranslated)</value> 
    143   </data> 
    144   <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve"> 
    145     <value>(Untranslated)</value> 
    146   </data> 
    147135</root> 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/Strings.nl.resx

    r2361 r2443  
    133133    <value>(Untranslated)</value> 
    134134  </data> 
    135   <data name="{0} (1 pass)" xml:space="preserve"> 
    136     <value>(Untranslated)</value> 
    137   </data> 
    138   <data name="{0} ({1} passes)" xml:space="preserve"> 
    139     <value>(Untranslated)</value> 
    140   </data> 
    141   <data name="Random" xml:space="preserve"> 
    142     <value>(Untranslated)</value> 
    143   </data> 
    144   <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve"> 
    145     <value>(Untranslated)</value> 
    146   </data> 
    147135</root> 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/Strings.pl.resx

    r2361 r2443  
    133133    <value>(Untranslated)</value> 
    134134  </data> 
    135   <data name="{0} (1 pass)" xml:space="preserve"> 
    136     <value>(Untranslated)</value> 
    137   </data> 
    138   <data name="{0} ({1} passes)" xml:space="preserve"> 
    139     <value>(Untranslated)</value> 
    140   </data> 
    141   <data name="Random" xml:space="preserve"> 
    142     <value>(Untranslated)</value> 
    143   </data> 
    144   <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve"> 
    145     <value>(Untranslated)</value> 
    146   </data> 
    147135</root> 
  • branches/eraser6/pluginsRewrite/Eraser.Plugins/Strings.resx

    r2361 r2443  
    133133    <value>The file system on the drive {0} is not supported.</value> 
    134134  </data> 
    135   <data name="{0} (1 pass)" xml:space="preserve"> 
    136     <value>{0} (1 pass)</value> 
    137   </data> 
    138   <data name="{0} ({1} passes)" xml:space="preserve"> 
    139     <value>{0} ({1} passes)</value> 
    140   </data> 
    141   <data name="Random" xml:space="preserve"> 
    142     <value>Random</value> 
    143   </data> 
    144   <data name="The selected erasure method is not supported for this erasure target." xml:space="preserve"> 
    145     <value>The selected erasure method is not supported for this erasure target.</value> 
    146   </data> 
    147135</root> 
Note: See TracChangeset for help on using the changeset viewer.