Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate System.IO.IsolatedStorage for nullable #31835

Merged
merged 3 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/libraries/Common/src/System/Security/IdentityHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Diagnostics;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -38,9 +39,9 @@ internal static string GetNormalizedUriHash(Uri uri)
/// Uses the AssemblyName's public key to generate a hash equivalent to what
/// StrongName.Normalize() gives.
/// </summary>
internal static string GetNormalizedStrongNameHash(AssemblyName name)
internal static string? GetNormalizedStrongNameHash(AssemblyName name)
{
byte[] publicKey = name.GetPublicKey();
byte[]? publicKey = name.GetPublicKey();

// If we don't have a key, we're not strong named
if (publicKey == null || publicKey.Length == 0)
Expand All @@ -51,8 +52,8 @@ internal static string GetNormalizedStrongNameHash(AssemblyName name)
using (BinaryWriter bw = new BinaryWriter(ms))
{
bw.Write(publicKey);
bw.Write(name.Version.Major);
bw.Write(name.Name);
bw.Write(name.Version!.Major);
bw.Write(name.Name!);

ms.Position = 0;
return GetStrongHashSuitableForObjectName(ms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ protected IsolatedStorage() { }
public virtual long UsedSize { get { throw null; } }
public virtual bool IncreaseQuotaTo(long newQuotaSize) { throw null; }
protected void InitStore(System.IO.IsolatedStorage.IsolatedStorageScope scope, System.Type appEvidenceType) { }
protected void InitStore(System.IO.IsolatedStorage.IsolatedStorageScope scope, System.Type domainEvidenceType, System.Type assemblyEvidenceType) { }
protected void InitStore(System.IO.IsolatedStorage.IsolatedStorageScope scope, System.Type? domainEvidenceType, System.Type? assemblyEvidenceType) { }
public abstract void Remove();
}
public partial class IsolatedStorageException : System.Exception
{
public IsolatedStorageException() { }
protected IsolatedStorageException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public IsolatedStorageException(string message) { }
public IsolatedStorageException(string message, System.Exception inner) { }
public IsolatedStorageException(string? message) { }
public IsolatedStorageException(string? message, System.Exception? inner) { }
}
public sealed partial class IsolatedStorageFile : System.IO.IsolatedStorage.IsolatedStorage, System.IDisposable
{
Expand Down Expand Up @@ -76,10 +76,10 @@ public void Dispose() { }
public static System.IO.IsolatedStorage.IsolatedStorageFile GetMachineStoreForApplication() { throw null; }
public static System.IO.IsolatedStorage.IsolatedStorageFile GetMachineStoreForAssembly() { throw null; }
public static System.IO.IsolatedStorage.IsolatedStorageFile GetMachineStoreForDomain() { throw null; }
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore(System.IO.IsolatedStorage.IsolatedStorageScope scope, object applicationIdentity) { throw null; }
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore(System.IO.IsolatedStorage.IsolatedStorageScope scope, object domainIdentity, object assemblyIdentity) { throw null; }
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore(System.IO.IsolatedStorage.IsolatedStorageScope scope, System.Type applicationEvidenceType) { throw null; }
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore(System.IO.IsolatedStorage.IsolatedStorageScope scope, System.Type domainEvidenceType, System.Type assemblyEvidenceType) { throw null; }
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore(System.IO.IsolatedStorage.IsolatedStorageScope scope, object? applicationIdentity) { throw null; }
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore(System.IO.IsolatedStorage.IsolatedStorageScope scope, object? domainIdentity, object? assemblyIdentity) { throw null; }
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore(System.IO.IsolatedStorage.IsolatedStorageScope scope, System.Type? applicationEvidenceType) { throw null; }
public static System.IO.IsolatedStorage.IsolatedStorageFile GetStore(System.IO.IsolatedStorage.IsolatedStorageScope scope, System.Type? domainEvidenceType, System.Type? assemblyEvidenceType) { throw null; }
public static System.IO.IsolatedStorage.IsolatedStorageFile GetUserStoreForApplication() { throw null; }
public static System.IO.IsolatedStorage.IsolatedStorageFile GetUserStoreForAssembly() { throw null; }
public static System.IO.IsolatedStorage.IsolatedStorageFile GetUserStoreForDomain() { throw null; }
Expand All @@ -99,10 +99,10 @@ public partial class IsolatedStorageFileStream : System.IO.FileStream
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access) : base (default(Microsoft.Win32.SafeHandles.SafeFileHandle), default(System.IO.FileAccess)) { }
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) : base (default(Microsoft.Win32.SafeHandles.SafeFileHandle), default(System.IO.FileAccess)) { }
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, int bufferSize) : base (default(Microsoft.Win32.SafeHandles.SafeFileHandle), default(System.IO.FileAccess)) { }
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, int bufferSize, System.IO.IsolatedStorage.IsolatedStorageFile isf) : base (default(Microsoft.Win32.SafeHandles.SafeFileHandle), default(System.IO.FileAccess)) { }
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.IO.IsolatedStorage.IsolatedStorageFile isf) : base (default(Microsoft.Win32.SafeHandles.SafeFileHandle), default(System.IO.FileAccess)) { }
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.IsolatedStorage.IsolatedStorageFile isf) : base (default(Microsoft.Win32.SafeHandles.SafeFileHandle), default(System.IO.FileAccess)) { }
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.IsolatedStorage.IsolatedStorageFile isf) : base (default(Microsoft.Win32.SafeHandles.SafeFileHandle), default(System.IO.FileAccess)) { }
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, int bufferSize, System.IO.IsolatedStorage.IsolatedStorageFile? isf) : base (default(Microsoft.Win32.SafeHandles.SafeFileHandle), default(System.IO.FileAccess)) { }
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.IO.IsolatedStorage.IsolatedStorageFile? isf) : base (default(Microsoft.Win32.SafeHandles.SafeFileHandle), default(System.IO.FileAccess)) { }
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.IsolatedStorage.IsolatedStorageFile? isf) : base (default(Microsoft.Win32.SafeHandles.SafeFileHandle), default(System.IO.FileAccess)) { }
public IsolatedStorageFileStream(string path, System.IO.FileMode mode, System.IO.IsolatedStorage.IsolatedStorageFile? isf) : base (default(Microsoft.Win32.SafeHandles.SafeFileHandle), default(System.IO.FileAccess)) { }
public override bool CanRead { get { throw null; } }
public override bool CanSeek { get { throw null; } }
public override bool CanWrite { get { throw null; } }
Expand All @@ -112,8 +112,8 @@ public partial class IsolatedStorageFileStream : System.IO.FileStream
public override long Length { get { throw null; } }
public override long Position { get { throw null; } set { } }
public override Microsoft.Win32.SafeHandles.SafeFileHandle SafeFileHandle { get { throw null; } }
public override System.IAsyncResult BeginRead(byte[] buffer, int offset, int numBytes, System.AsyncCallback userCallback, object stateObject) { throw null; }
public override System.IAsyncResult BeginWrite(byte[] buffer, int offset, int numBytes, System.AsyncCallback userCallback, object stateObject) { throw null; }
public override System.IAsyncResult BeginRead(byte[] buffer, int offset, int numBytes, System.AsyncCallback userCallback, object? stateObject) { throw null; }
public override System.IAsyncResult BeginWrite(byte[] buffer, int offset, int numBytes, System.AsyncCallback userCallback, object? stateObject) { throw null; }
protected override void Dispose(bool disposing) { }
public override System.Threading.Tasks.ValueTask DisposeAsync() { throw null; }
public override int EndRead(System.IAsyncResult asyncResult) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configurations>$(NetCoreAppCurrent)-Debug;$(NetCoreAppCurrent)-Release</Configurations>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.IO.IsolatedStorage.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configurations>$(NetCoreAppCurrent)-Unix-Debug;$(NetCoreAppCurrent)-Unix-Release;$(NetCoreAppCurrent)-Windows_NT-Debug;$(NetCoreAppCurrent)-Windows_NT-Release</Configurations>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="System\IO\IsolatedStorage\IsolatedStorageException.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of files referenced in test proj and failing build

using System.Reflection;
using System.Security;
using System.Threading;
Expand All @@ -28,7 +29,7 @@ internal static string GetDataDirectory(IsolatedStorageScope scope)
return dataDirectory;
}

internal static void GetDefaultIdentityAndHash(out object identity, out string hash, char separator)
internal static void GetDefaultIdentityAndHash(out object identity, out string? hash, char separator)
{
// In .NET Framework IsolatedStorage uses identity from System.Security.Policy.Evidence to build
// the folder structure on disk. It would use the "best" available evidence in this order:
Expand All @@ -48,13 +49,13 @@ internal static void GetDefaultIdentityAndHash(out object identity, out string h
// to pull from we'd have to dig into the use case to try and find a reasonable solution should we
// run into this in the wild.

Assembly assembly = Assembly.GetEntryAssembly();
Assembly? assembly = Assembly.GetEntryAssembly();

if (assembly == null)
throw new IsolatedStorageException(SR.IsolatedStorage_Init);

AssemblyName assemblyName = assembly.GetName();
Uri codeBase = new Uri(assembly.CodeBase);
Uri codeBase = new Uri(assembly.CodeBase!);

hash = IdentityHelper.GetNormalizedStrongNameHash(assemblyName);
if (hash != null)
Expand All @@ -71,7 +72,7 @@ internal static void GetDefaultIdentityAndHash(out object identity, out string h

internal static string GetRandomDirectory(string rootDirectory, IsolatedStorageScope scope)
{
string randomDirectory = GetExistingRandomDirectory(rootDirectory);
string? randomDirectory = GetExistingRandomDirectory(rootDirectory);
if (string.IsNullOrEmpty(randomDirectory))
{
using (Mutex m = CreateMutexNotOwned(rootDirectory))
Expand Down Expand Up @@ -101,7 +102,7 @@ internal static string GetRandomDirectory(string rootDirectory, IsolatedStorageS
return randomDirectory;
}

internal static string GetExistingRandomDirectory(string rootDirectory)
internal static string? GetExistingRandomDirectory(string rootDirectory)
{
// Look for an existing random directory at the given root
// (a set of nested directories that were created via Path.GetRandomFileName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
namespace System.IO.IsolatedStorage
{
internal static partial class Helper
{
private const string IsolatedStorageDirectoryName = "IsolatedStorage";

private static string s_machineRootDirectory;
private static string s_roamingUserRootDirectory;
private static string s_userRootDirectory;
private static string? s_machineRootDirectory;
private static string? s_roamingUserRootDirectory;
private static string? s_userRootDirectory;

/// <summary>
/// The full root directory is the relevant special folder from Environment.GetFolderPath() plus "IsolatedStorage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public abstract class IsolatedStorage : MarshalByRefObject
private ulong _quota;
private bool _validQuota;

private object _applicationIdentity;
private object _assemblyIdentity;
private object _domainIdentity;
private object? _applicationIdentity;
private object? _assemblyIdentity;
private object? _domainIdentity;

protected IsolatedStorage() { }

Expand All @@ -22,7 +22,7 @@ public object ApplicationIdentity
get
{
if (Helper.IsApplication(Scope))
return _applicationIdentity;
return _applicationIdentity!;

throw new InvalidOperationException(SR.IsolatedStorage_ApplicationUndefined);
}
Expand All @@ -33,7 +33,7 @@ public object AssemblyIdentity
get
{
if (Helper.IsAssembly(Scope))
return _assemblyIdentity;
return _assemblyIdentity!;

throw new InvalidOperationException(SR.IsolatedStorage_AssemblyUndefined);
}
Expand All @@ -44,7 +44,7 @@ public object DomainIdentity
get
{
if (Helper.IsDomain(Scope))
return _domainIdentity;
return _domainIdentity!;

throw new InvalidOperationException(SR.IsolatedStorage_AssemblyUndefined);
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public virtual bool IncreaseQuotaTo(long newQuotaSize)

public abstract void Remove();

internal string IdentityHash
internal string? IdentityHash
{
get; private set;
}
Expand All @@ -138,14 +138,12 @@ protected void InitStore(IsolatedStorageScope scope, Type appEvidenceType)
InitStore(scope, null, appEvidenceType);
}

protected void InitStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType)
protected void InitStore(IsolatedStorageScope scope, Type? domainEvidenceType, Type? assemblyEvidenceType)
{
VerifyScope(scope);
Scope = scope;

object identity;
string hash;
Helper.GetDefaultIdentityAndHash(out identity, out hash, SeparatorInternal);
Helper.GetDefaultIdentityAndHash(out object identity, out string? hash, SeparatorInternal);

if (Helper.IsApplication(scope))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ public class IsolatedStorageException : Exception, ISerializable

// All the exceptions from IsolatedStorage are wrapped as IsolatedStorageException,
// this field is used to provide the underlying exception under debugger.
internal Exception _underlyingException;
internal Exception? _underlyingException;

public IsolatedStorageException()
: base(SR.IsolatedStorage_Exception)
{
HResult = COR_E_ISOSTORE;
}

public IsolatedStorageException(string message)
public IsolatedStorageException(string? message)
: base(message)
{
HResult = COR_E_ISOSTORE;
}

public IsolatedStorageException(string message, Exception inner)
public IsolatedStorageException(string? message, Exception? inner)
: base(message, inner)
{
HResult = COR_E_ISOSTORE;
Expand Down
Loading