C# Bouncy Castle FipsDRBG - c#

I'm trying to access a few things from FipsDRBG class.
My code is shown below. How do I access fromEntropySource()? This function is within the internal class Base in FipsDRBG.
MyEntropyProvider entropyProvider = new MyEntropyProvider(#params);
FipsDrbg.BuilderService shaAlgo = FipsDrbg.Sha1; // Here I tried to use FipsDrbg.Base but then again it is internal
FipsDrbg.Builder builder = shaAlgo.fromEntropySource(entropyProvider);
I've compared C# FipsDrbg with Java FipsDrbg. In Java, all classes are declared public which is why I can access them easily. I can neither access FipsDrbg.Base or fromEntropySource().
Can someone please suggest how to proceed with this?

I could access all the FIPS related code after getting a paid version of the library. It has great support for all the FIPS related functions which may or may not be available in the free version.

Related

Where is the source code for CSharpSyntaxVisitor virtual method *declarations* such as VisitQualifiedName, VisitAwaitExpression etc?

Looking at the online source for CSharpSyntaxVisitor there are just a small number of default members.
Implementing a CSharpSyntaxWalker, which derives from CSharpSyntaxVisitor, there are many virtual methods to override, for visiting syntax elements in C#.
Where are these defined/declared?
CSharpSyntaxVisitor is implemented as a partial class, but searching on github I was unable to locate where the basic version of the class is extended with the syntax elements.
Can someone please help point me to where this stuff is defined?
You'll find them in Syntax.xml.Main.Generated.cs. This code used to be generated by a tool, from a file called Syntax.xml.
These days, it looks like it's generated using a Source Generator. The source generator is called SourceGenerator, and the bit which generates the additional partial class for CSharpSyntaxVisitor containing those extra Visit methods is here. It still reads its input from Syntax.xml.

rangeOfComposedCharacterSequenceAtIndex in Xamarin?

I'm trying to port the iosMath LaTeX library to C#. iosMath uses NSString's rangeOfComposedCharacterSequenceAtIndex in certain places. But I can't find any equivalent in Xamarin's NSString API. What am I missing? Is this functionality available some other way? If so, how?
Cross-posted on the Xamarin forums here.
Is this functionality available some other way?
We have to implement it by ourselves using C# if the api can not be found in the Class.
For example :
rangeOfString in NSString also can't be found ,and we can create the method instead.
static NSRange CalcRangeFor (string source, string substring)
{
var range = new NSRange {
Location = source.IndexOf (substring),
Length = substring.Length
};
return range;
}
However, rangeOfComposedCharacterSequenceAtIndex is a bit of complex, you can search the source code and implement with your new method. But I'm afraid it is still hard to do the work, since it is related to CoreFoundtion and we know little about it.
So why didn't you try to create a binding project? You don't have to transform the code from objective-c to c# but need some extra works for binding.
Refer to Binding iOS Libraries

Creating new Excel formulas/functions with C#

We are looking to be able to programmatically create an Excel workbook which would call custom code from within a cell. Cells would look something like:
=MyCode(A1:A10)
My first thought was to use VBA, but since the algorithm is proprietary the powers that be want it to be protected. I can put a password on it, but it is well documented (here on StackOverflow) on how to get around such passwords.
My second thought was to create an Excel 2013 Workbook project in Visual Studio, but I haven't found anything useful on how to expose a function in C# so it can be called like I described.
Next I thought about having VBA call the C#, and found instructions at https://msdn.microsoft.com/en-us/library/bb608613.aspx. I followed those instructions to the letter, but when I try to run the VBA code I get an error with the GetManagedClass function: Object Library Feature not Supported.
Are there any good references on how to do something like this?
You're looking for Excel-DNA.
This open-source library allows you to create managed Excel add-ins, and supports making user-defined functions, but also macros, real-time RTD data sources etc.
Creating an Excel UDF in C# is then as simple as:
[ExcelFunction(Description = "My first .NET function")]
public static string SayHello(string name)
{
return "Hello " + name;
}
and you can call from a cell as:
=SayHello("Walter")
For code protection with .NET, you'd need to use an obfuscator - there are a variety of free and paid-for ones available.
I have also tried this sample, with the same error. I found a solution that worked for me.
In the ISheet1.cs file, replace the ISheet1 interface declaration with the following code. This code makes the ISheet1 interface public, and it applies the http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.comvisibleattribute.aspx attribute to make the interface visible to COM.
C#
[System.Runtime.InteropServices.ComVisible(true)]
public interface ISheet1
{
void CreateVstoNamedRange(Microsoft.Office.Interop.Excel.Range range, string name);
}
Full article her: http://www.nullskull.com/q/10059408/c-code-to-set-excel-workbook-macro-enabled-and-to-trust-vba-projects.aspx

Parsing C# code for contextually aware semantic highlighting

I'm working on a semantic highlighting plugin for VS. Here you can see a web Example.
The goal:
Acquiring all variables and creating different Classifications for every one of them.
The problem:
Getting the variables from the code without writing a C# lexer.
My current approach uses an ITagger. I use an ITagAggregator to get the tags of all the spans that get passed to the ITagger. Then I filter those and get only spans with the "identifier" classification which includes varibles, methods names, class names, usings and properties.
public class Classifier : ITagger<ClassificationTag> {
public IEnumerable<ITagSpan<ClassificationTag>> GetTags(NormalizedSnapshotSpanCollection spans) {
ITextSnapshot snapshot = spans[0].Snapshot;
var tags = _aggregator.GetTags(spans).Where((span) => span.Tag.ClassificationType.Classification.Equals("identifier")).ToArray();
foreach(var classifiedSpan in tags) {
foreach(SnapshotSpan span in classifiedSpan.Span.GetSpans(snapshot)) {
//generate classification based on variable name
yield return new TagSpan<ClassificationTag>(span, new ClassificationTag(_classification));
}
}
}
}
It would be a lot easier to use the builtin C# Lexer to get a list of all variables bundled to a bunch of meta data. Is this data available for plugin development? Is there an alternative way I could acquire it, if not?
The problem: Getting the variables from the code without writing a C# lexer.
Roslyn can do this: https://roslyn.codeplex.com/
There's even a Syntax Visualizer sample that might interest you. I also found an example using Roslyn to create a Syntax Highlighter.
Visual Studio exposes that information as a code model.
Here is an example how you can access class, and then find attribute on the class, and parse attribute arguments:
Accessing attribute info from DTE
Here is more information about code models:
http://msdn.microsoft.com/en-us/library/ms228763.aspx
Here's also automation object model chart what I've been using quite few times: http://msdn.microsoft.com/en-us/library/za2b25t3.aspx
Also, as said, Roslyn is indeed also a possible option. Here is an example for VS2015 using roslyn: https://github.com/tomasr/roslyn-colorizer/blob/master/RoslynColorizer/RoslynColorizer.cs
For building language tools if may be better to use a parser generator for C#. The GOLD parsing system is one such toolkit which can handle LALR grammars. It has a .NET component based engine that you can use in your project and it can be used to integrate with any IDE. You can also find the grammars for various programming languages including C#.

What happened to .ToShortDateString in .NET Portable Class Library

I am wondering why there is no .ToShortDateString in the .NET Portable Class Library. I have 2 projects (Silverlight, and regular .NET Class Library) that use the same code, and the code involves calling .ToShortDateString() on a DateTime object. In order to reuse the same code instead of copying it in 2 places, I created a portable class library so it can be imported by both Silverlight and .NET Class Library. Unfortunately, it doesn't seem like .ToShortDateString() is available when using the class library. I can accept a string parameter in the portable class library method and pass the .ToShortDateString() value from both silverlight and class library projects, but I am wondering why this method isn't native for the portable library. Is it a culture issue?
It was removed to deemphasize its use from what we consider the "modern" surface area, which I hint about here (What is .NET Portable Subset (Legacy)?). This means that it does not show up newer platforms (such as Windows Store apps) and does not show up in portable libraries.
You can mimic its behavior by simply passing "d" to DateTime.ToString().
We wanted to deemphasize its use because it is the only .NET Framework date format that does not have a representation at the Windows OS level. This causes it to not reflect/respect the formatting changes made by the user. In certain organizations and governments, it is important that these settings are respected.
While most of methods/properties that belong to types defined in System namespace are available in PCLs, there are some exceptions, and ToShortDateString is one of them. Below is the list of portable DateTime members. I don't know what was the reason behind the exclusion of some string conversion methods, but I guess this is due to redundancy. As cadrell0 pointed out, you can always achieve the same by using ToString with a parameter.
T:System.DateTime
M:System.DateTime.ToString(System.String)
M:System.DateTime.op_GreaterThan(System.DateTime,System.DateTime)
M:System.DateTime.ParseExact(System.String,System.String[],System.IFormatProvider,System.Globalization.DateTimeStyles)
M:System.DateTime.get_Month
M:System.DateTime.FromFileTimeUtc(System.Int64)
M:System.DateTime.get_Date
M:System.DateTime.get_TimeOfDay
M:System.DateTime.get_Kind
M:System.DateTime.ToUniversalTime
M:System.DateTime.get_Year
M:System.DateTime.op_Subtraction(System.DateTime,System.TimeSpan)
M:System.DateTime.get_Second
M:System.DateTime.get_DayOfWeek
M:System.DateTime.TryParse(System.String,System.IFormatProvider,System.Globalization.DateTimeStyles,System.DateTime#)
M:System.DateTime.#ctor(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)
M:System.DateTime.get_Day
P:System.DateTime.Date
M:System.DateTime.op_Addition(System.DateTime,System.TimeSpan)
M:System.DateTime.IsDaylightSavingTime
M:System.DateTime.get_DayOfYear
M:System.DateTime.ToFileTime
M:System.DateTime.Subtract(System.DateTime)
M:System.DateTime.IsLeapYear(System.Int32)
M:System.DateTime.#ctor(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.DateTimeKind)
M:System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider,System.Globalization.DateTimeStyles)
P:System.DateTime.Day
M:System.DateTime.get_Hour
M:System.DateTime.Equals(System.DateTime)
M:System.DateTime.get_UtcNow
M:System.DateTime.get_Today
M:System.DateTime.TryParse(System.String,System.DateTime#)
P:System.DateTime.Kind
M:System.DateTime.System#IComparable#CompareTo(System.Object)
P:System.DateTime.UtcNow
P:System.DateTime.Hour
P:System.DateTime.Millisecond
M:System.DateTime.Parse(System.String)
F:System.DateTime.MinValue
M:System.DateTime.op_GreaterThanOrEqual(System.DateTime,System.DateTime)
M:System.DateTime.#ctor(System.Int64,System.DateTimeKind)
M:System.DateTime.GetHashCode
P:System.DateTime.Year
M:System.DateTime.Add(System.TimeSpan)
M:System.DateTime.Equals(System.DateTime,System.DateTime)
M:System.DateTime.ToString(System.IFormatProvider)
M:System.DateTime.get_Now
P:System.DateTime.Month
M:System.DateTime.DaysInMonth(System.Int32,System.Int32)
M:System.DateTime.AddMinutes(System.Double)
M:System.DateTime.get_Minute
M:System.DateTime.#ctor(System.Int64)
M:System.DateTime.op_LessThanOrEqual(System.DateTime,System.DateTime)
M:System.DateTime.ToString(System.String,System.IFormatProvider)
P:System.DateTime.DayOfYear
M:System.DateTime.AddMilliseconds(System.Double)
P:System.DateTime.Second
P:System.DateTime.DayOfWeek
M:System.DateTime.op_Equality(System.DateTime,System.DateTime)
M:System.DateTime.#ctor(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)
M:System.DateTime.TryParseExact(System.String,System.String,System.IFormatProvider,System.Globalization.DateTimeStyles,System.DateTime#)
M:System.DateTime.ToFileTimeUtc
P:System.DateTime.Today
M:System.DateTime.op_LessThan(System.DateTime,System.DateTime)
M:System.DateTime.get_Millisecond
M:System.DateTime.op_Subtraction(System.DateTime,System.DateTime)
M:System.DateTime.#ctor(System.Int32,System.Int32,System.Int32)
M:System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider)
M:System.DateTime.AddSeconds(System.Double)
M:System.DateTime.AddMonths(System.Int32)
M:System.DateTime.AddYears(System.Int32)
M:System.DateTime.Parse(System.String,System.IFormatProvider,System.Globalization.DateTimeStyles)
M:System.DateTime.get_Ticks
P:System.DateTime.Ticks
M:System.DateTime.TryParseExact(System.String,System.String[],System.IFormatProvider,System.Globalization.DateTimeStyles,System.DateTime#)
M:System.DateTime.ToLocalTime
M:System.DateTime.op_Inequality(System.DateTime,System.DateTime)
M:System.DateTime.SpecifyKind(System.DateTime,System.DateTimeKind)
M:System.DateTime.AddHours(System.Double)
P:System.DateTime.Minute
M:System.DateTime.Subtract(System.TimeSpan)
M:System.DateTime.#ctor(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.DateTimeKind)
F:System.DateTime.MaxValue
M:System.DateTime.ToString
M:System.DateTime.FromFileTime(System.Int64)
P:System.DateTime.TimeOfDay
M:System.DateTime.Compare(System.DateTime,System.DateTime)
M:System.DateTime.CompareTo(System.DateTime)
M:System.DateTime.Parse(System.String,System.IFormatProvider)
M:System.DateTime.AddDays(System.Double)
P:System.DateTime.Now
M:System.DateTime.Equals(System.Object)
M:System.DateTime.AddTicks(System.Int64)

Categories

Resources