public Type GetDynamicClass(IEnumerable<DynamicProperty> properties, Type resultType = null, Type baseType = null) { rwLock.AcquireReaderLock(Timeout.Infinite); try { Signature signature = new Signature(properties); Type type; if (!classes.TryGetValue(signature, out type)) { if (resultType == null) type = CreateDynamicClass(signature.properties); else { type = CreateDynamicClass(signature.properties, resultType, baseType); } classes.Add(signature, type); } return type; } finally { rwLock.ReleaseReaderLock(); } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures) { if (!session.TextView.Properties.ContainsProperty(SessionKey)) { return; } // Map the trigger point down to our buffer. var subjectTriggerPoint = session.GetTriggerPoint(subjectBuffer.CurrentSnapshot); if (!subjectTriggerPoint.HasValue) { return; } var currentSnapshot = subjectTriggerPoint.Value.Snapshot; var querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0); var applicableToSpan = currentSnapshot.CreateTrackingSpan( querySpan.Start.Position, 0, SpanTrackingMode.EdgeInclusive); string encouragement = encouragements.GetRandomEncouragement(); var signature = new Signature(applicableToSpan, encouragement, "", ""); signatures.Add(signature); }
internal object[] CheckArguments(object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig) { int num = (parameters != null) ? parameters.Length : 0; object[] objArray = new object[num]; ParameterInfo[] parametersNoCopy = null; for (int i = 0; i < num; i++) { object defaultValue = parameters[i]; RuntimeType type = sig.Arguments[i]; if (defaultValue == Type.Missing) { if (parametersNoCopy == null) { parametersNoCopy = this.GetParametersNoCopy(); } if (parametersNoCopy[i].DefaultValue == DBNull.Value) { throw new ArgumentException(Environment.GetResourceString("Arg_VarMissNull"), "parameters"); } defaultValue = parametersNoCopy[i].DefaultValue; } objArray[i] = type.CheckValue(defaultValue, binder, culture, invokeAttr); } return objArray; }
public AuthorizationHeader(ClientCredentials credentials, Nonce nonce, TimeStamp timestamp, Signature signature) { this.credentials = credentials; this.timestamp = timestamp; this.nonce = nonce; this.signature = signature; }
public void CanCommitALittleBit() { SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); using (var repo = Repository.Init(scd.DirectoryPath)) { string dir = repo.Info.Path; Path.IsPathRooted(dir).ShouldBeTrue(); Directory.Exists(dir).ShouldBeTrue(); const string relativeFilepath = "new.txt"; string filePath = Path.Combine(repo.Info.WorkingDirectory, relativeFilepath); File.WriteAllText(filePath, "null"); repo.Index.Stage(relativeFilepath); File.AppendAllText(filePath, "token\n"); repo.Index.Stage(relativeFilepath); repo.Head[relativeFilepath].ShouldBeNull(); var author = new Signature("Author N. Ame", "*****@*****.**", DateTimeOffset.Now.AddSeconds(-10)); Commit commit = repo.Commit("Initial egotistic commit", author, author); AssertBlobContent(repo.Head[relativeFilepath], "nulltoken\n"); AssertBlobContent(commit[relativeFilepath], "nulltoken\n"); commit.Parents.Count().ShouldEqual(0); repo.Info.IsEmpty.ShouldBeFalse(); File.WriteAllText(filePath, "nulltoken commits!\n"); repo.Index.Stage(relativeFilepath); var author2 = new Signature(author.Name, author.Email, author.When.AddSeconds(5)); Commit commit2 = repo.Commit("Are you trying to fork me?", author2, author2); AssertBlobContent(repo.Head[relativeFilepath], "nulltoken commits!\n"); AssertBlobContent(commit2[relativeFilepath], "nulltoken commits!\n"); commit2.Parents.Count().ShouldEqual(1); commit2.Parents.First().Id.ShouldEqual(commit.Id); Branch firstCommitBranch = repo.CreateBranch("davidfowl-rules", commit.Id.Sha); //TODO: This cries for a shortcut method :-/ repo.Branches.Checkout(firstCommitBranch.Name); //TODO: This cries for a shortcut method :-/ File.WriteAllText(filePath, "davidfowl commits!\n"); var author3 = new Signature("David Fowler", "*****@*****.**", author.When.AddSeconds(2)); repo.Index.Stage(relativeFilepath); Commit commit3 = repo.Commit("I'm going to branch you backwards in time!", author3, author3); AssertBlobContent(repo.Head[relativeFilepath], "davidfowl commits!\n"); AssertBlobContent(commit3[relativeFilepath], "davidfowl commits!\n"); commit3.Parents.Count().ShouldEqual(1); commit3.Parents.First().Id.ShouldEqual(commit.Id); AssertBlobContent(firstCommitBranch[relativeFilepath], "nulltoken\n"); } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList<ISignature> signatures) { if (!session.TextView.Properties.ContainsProperty(SessionKey)) { return; } // At the moment there is a bug in the javascript provider which causes it to // repeatedly insert the same Signature values into an ISignatureHelpSession // instance. There is no way, other than reflection, for us to prevent this // from happening. Instead we just ensure that our provider runs after // Javascript and then remove the values they add here signatures.Clear(); // Map the trigger point down to our buffer. var subjectTriggerPoint = session.GetTriggerPoint(subjectBuffer.CurrentSnapshot); if (!subjectTriggerPoint.HasValue) { return; } var currentSnapshot = subjectTriggerPoint.Value.Snapshot; var querySpan = new SnapshotSpan(subjectTriggerPoint.Value, 0); var applicableToSpan = currentSnapshot.CreateTrackingSpan( querySpan.Start.Position, 0, SpanTrackingMode.EdgeInclusive); string encouragement = encouragements.GetRandomEncouragement(); if (encouragement != null) { var signature = new Signature(applicableToSpan, encouragement, "", ""); signatures.Add(signature); } }
/// <summary> /// Creates a signature for the given messsage and the given private key. /// </summary> /// <param name="message">The message.</param> /// <param name="privateKey">The array of 32 bytes of the private key.</param> /// <param name="useCompressedPublicKey">true to specify that the public key should have the compressed format; otherwise, false.</param> /// <exception cref="ArgumentException">The message is null or private key is null or invalid.</exception> /// <returns>The signature for the given message and the given private key in base-64 encoding.</returns> public static string SingMesssage(string message, byte[] privateKey, bool useCompressedPublicKey) { if (message == null) { throw new ArgumentException("The message is null.", nameof(message)); } if (privateKey == null) { throw new ArgumentException("The private key is null.", nameof(privateKey)); } if (!BitcoinPrivateKey.IsValid(privateKey)) { throw new ArgumentException("The private key is invalid.", nameof(privateKey)); } ECPrivateKeyParameters parameters = new ECPrivateKeyParameters(new BigInteger(1, privateKey), domainParameters); ECDsaSigner signer = new ECDsaSigner(new HMacDsaKCalculator(new Sha256Digest())); signer.Init(true, parameters); var hash = GetMessageHash(message); BigInteger[] signatureArray = signer.GenerateSignature(hash); BigInteger r = signatureArray[0]; BigInteger s = signatureArray[1]; s = NormalizeS(s); byte[] encodedPublicKey = BitcoinPrivateKey.ToEncodedPublicKey(privateKey, useCompressedPublicKey); int pubKeyMaskOffset = useCompressedPublicKey ? 4 : 0; Signature signature = null; for (int i = 0; i < 4; i++) { Signature candidateSignature = new Signature(); candidateSignature.PublicKeyMask = i + pubKeyMaskOffset; candidateSignature.R = r; candidateSignature.S = s; byte[] recoveredPublicKey = RecoverPublicKeyFromSignature(hash, candidateSignature); if (recoveredPublicKey != null && recoveredPublicKey.SequenceEqual(encodedPublicKey)) { signature = candidateSignature; break; } } if (signature == null) { // this should not happen throw new Exception("The public key is not recoverable from signature."); } return EncodeSignature(signature); }
internal ParameterInfo(ParameterInfo accessor, MethodBuilderInstantiation method) : this(accessor, (MemberInfo) method) { this.m_signature = accessor.m_signature; if (this.ClassImpl.IsGenericParameter) { this.ClassImpl = method.GetGenericArguments()[this.ClassImpl.GenericParameterPosition]; } }
private void UpdateFromMem(IntPtr sigPtr) { _gpgme_op_verify_result ver = new _gpgme_op_verify_result(); Marshal.PtrToStructure(sigPtr, ver); file_name = Gpgme.PtrToStringUTF8(ver.file_name); if (ver.signature != IntPtr.Zero) signature = new Signature(ver.signature); }
public UpdateInfo(string updateVersion, Uri downloadURI, long downloadSize, Signature signature) { _updateVersion = updateVersion; _downloadURI = downloadURI; _downloadSize = downloadSize; _signature = signature; if (_signature.SigningCertificate.Capability != CertificateCapability.SignFile) throw new Exception("Signing certificate is not capable to sign files."); }
private ParameterInfo(Signature signature, MetadataImport scope, int tkParamDef, int position, ParameterAttributes attributes, MemberInfo member) { this.PositionImpl = position; this.MemberImpl = member; this.m_signature = signature; this.m_tkParamDef = System.Reflection.MetadataToken.IsNullToken(tkParamDef) ? 0x8000000 : tkParamDef; this.m_scope = scope; this.AttrsImpl = attributes; this.ClassImpl = null; this.NameImpl = null; }
public TypeDecoderMethodAttribute(Type[] dependency) { try { m_dependency = new Signature(dependency[0], dependency[1]); } catch (Exception) { // TODO: wrongly constructed dependency } }
public Type GetDynamicClass(IEnumerable<DynamicProperty> properties) { Type type; Signature key = new Signature(properties); if (!this.classes.TryGetValue(key, out type)) { type = this.CreateDynamicClass(key.properties); this.classes.Add(key, type); } return type; }
public Type GetDynamicClass( IEnumerable< DynamicProperty > properties ) { rwLock.AcquireReaderLock( Timeout.Infinite ); try { var signature = new Signature( properties ); Type type; if ( !classes.TryGetValue( signature , out type ) ) { type = CreateDynamicClass( signature.properties ); classes.Add( signature , type ); } return type; } finally { rwLock.ReleaseReaderLock(); } }
public async Task CanCreateAndRetrieveCommit() { string owner = this._repository.Owner.Login; var author = new Signature { Name = "author", Email = "*****@*****.**", Date = DateTime.UtcNow }; var commiter = new Signature { Name = "commiter", Email = "*****@*****.**", Date = DateTime.Today }; var newCommit = new NewCommit("test-commit", "[Change this to tree sha]", Enumerable.Empty<string>()) { Author = author, Committer = commiter }; var commit = await this._commitsClient.Create(owner, this._repository.Name, newCommit); Assert.NotNull(commit); var retrieved = await this._commitsClient.Get(owner, this._repository.Name, commit.Sha); Assert.NotNull(retrieved); }
private static Commit AddCommitToRepo(IRepository repo) { string relativeFilepath = "test.txt"; Touch(repo.Info.WorkingDirectory, relativeFilepath, content); repo.Index.Stage(relativeFilepath); var ie = repo.Index[relativeFilepath]; Assert.NotNull(ie); Assert.Equal("9daeafb9864cf43055ae93beb0afd6c7d144bfa4", ie.Id.Sha); var author = new Signature("nulltoken", "*****@*****.**", DateTimeOffset.Parse("Wed, Dec 14 2011 08:29:03 +0100")); var commit = repo.Commit("Initial commit", author, author); relativeFilepath = "big.txt"; var zeros = new string('0', 32*1024 + 3); Touch(repo.Info.WorkingDirectory, relativeFilepath, zeros); repo.Index.Stage(relativeFilepath); ie = repo.Index[relativeFilepath]; Assert.NotNull(ie); Assert.Equal("6518215c4274845a759cb498998fe696c42e3e0f", ie.Id.Sha); return commit; }
internal static bool DiffSigs(Signature sig1, RuntimeTypeHandle typeHandle1, Signature sig2, RuntimeTypeHandle typeHandle2) { SignatureStruct left = (SignatureStruct) sig1; SignatureStruct right = (SignatureStruct) sig2; return CompareSig(ref left, typeHandle1, ref right, typeHandle2); }
private RuntimeParameterInfo( Signature signature, MetadataImport scope, int tkParamDef, int position, ParameterAttributes attributes, MemberInfo member) { Contract.Requires(member != null); Contract.Assert(MdToken.IsNullToken(tkParamDef) == scope.Equals(MetadataImport.EmptyImport)); Contract.Assert(MdToken.IsNullToken(tkParamDef) || MdToken.IsTokenOfType(tkParamDef, MetadataTokenType.ParamDef)); PositionImpl = position; MemberImpl = member; m_signature = signature; m_tkParamDef = MdToken.IsNullToken(tkParamDef) ? (int)MetadataTokenType.ParamDef : tkParamDef; m_scope = scope; AttrsImpl = attributes; ClassImpl = null; NameImpl = null; }
// used by RuntimePropertyInfo internal RuntimeParameterInfo(RuntimeParameterInfo accessor, RuntimePropertyInfo property) : this(accessor, (MemberInfo)property) { m_signature = property.Signature; }
[System.Security.SecurityCritical] // auto-generated internal unsafe static ParameterInfo[] GetParameters( IRuntimeMethodInfo methodHandle, MemberInfo member, Signature sig, out ParameterInfo returnParameter, bool fetchReturnParameter) { returnParameter = null; int sigArgCount = sig.Arguments.Length; ParameterInfo[] args = fetchReturnParameter ? null : new ParameterInfo[sigArgCount]; int tkMethodDef = RuntimeMethodHandle.GetMethodDef(methodHandle); int cParamDefs = 0; // Not all methods have tokens. Arrays, pointers and byRef types do not have tokens as they // are generated on the fly by the runtime. if (!MdToken.IsNullToken(tkMethodDef)) { MetadataImport scope = RuntimeTypeHandle.GetMetadataImport(RuntimeMethodHandle.GetDeclaringType(methodHandle)); MetadataEnumResult tkParamDefs; scope.EnumParams(tkMethodDef, out tkParamDefs); cParamDefs = tkParamDefs.Length; // Not all parameters have tokens. Parameters may have no token // if they have no name and no attributes. if (cParamDefs > sigArgCount + 1 /* return type */) throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch")); for (int i = 0; i < cParamDefs; i++) { #region Populate ParameterInfos ParameterAttributes attr; int position, tkParamDef = tkParamDefs[i]; scope.GetParamDefProps(tkParamDef, out position, out attr); position--; if (fetchReturnParameter == true && position == -1) { // more than one return parameter? if (returnParameter != null) throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch")); returnParameter = new RuntimeParameterInfo(sig, scope, tkParamDef, position, attr, member); } else if (fetchReturnParameter == false && position >= 0) { // position beyong sigArgCount? if (position >= sigArgCount) throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch")); args[position] = new RuntimeParameterInfo(sig, scope, tkParamDef, position, attr, member); } #endregion } } // Fill in empty ParameterInfos for those without tokens if (fetchReturnParameter) { if (returnParameter == null) { returnParameter = new RuntimeParameterInfo(sig, MetadataImport.EmptyImport, 0, -1, (ParameterAttributes)0, member); } } else { if (cParamDefs < args.Length + 1) { for (int i = 0; i < args.Length; i++) { if (args[i] != null) continue; args[i] = new RuntimeParameterInfo(sig, MetadataImport.EmptyImport, 0, i, (ParameterAttributes)0, member); } } } return args; }
internal extern static object InvokeMethod(object target, object[] arguments, Signature sig, bool constructor);
internal static object InvokeMethodFast(IRuntimeMethodInfo method, object target, object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) { SignatureStruct signature = sig.m_signature; object result = RuntimeMethodHandle._InvokeMethodFast(method, target, arguments, ref signature, methodAttributes, typeOwner); sig.m_signature = signature; return result; }
private Signature GetNextSignature() { _signature = _signature.TimeShift(TimeSpan.FromMinutes(1)); return _signature; }
private static void CommitToANewRepository(string path) { using (Repository repo = Repository.Init(path)) { const string relativeFilepath = "test.txt"; string filePath = Path.Combine(repo.Info.WorkingDirectory, relativeFilepath); File.WriteAllText(filePath, "test\n"); repo.Index.Stage(relativeFilepath); var author = new Signature("nulltoken", "*****@*****.**", DateTimeOffset.Parse("Wed, Dec 14 2011 08:29:03 +0100")); repo.Commit("Initial commit", author, author); } }
public void CanCommitALittleBit() { SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); using (var repo = Repository.Init(scd.DirectoryPath)) { string dir = repo.Info.Path; Assert.True(Path.IsPathRooted(dir)); Assert.True(Directory.Exists(dir)); const string relativeFilepath = "new.txt"; string filePath = Path.Combine(repo.Info.WorkingDirectory, relativeFilepath); File.WriteAllText(filePath, "null"); repo.Index.Stage(relativeFilepath); File.AppendAllText(filePath, "token\n"); repo.Index.Stage(relativeFilepath); Assert.Null(repo.Head[relativeFilepath]); var author = DummySignature; Commit commit = repo.Commit("Initial egotistic commit", author, author); AssertBlobContent(repo.Head[relativeFilepath], "nulltoken\n"); AssertBlobContent(commit[relativeFilepath], "nulltoken\n"); Assert.Equal(0, commit.ParentsCount); Assert.False(repo.Info.IsEmpty); File.WriteAllText(filePath, "nulltoken commits!\n"); repo.Index.Stage(relativeFilepath); var author2 = new Signature(author.Name, author.Email, author.When.AddSeconds(5)); Commit commit2 = repo.Commit("Are you trying to fork me?", author2, author2); AssertBlobContent(repo.Head[relativeFilepath], "nulltoken commits!\n"); AssertBlobContent(commit2[relativeFilepath], "nulltoken commits!\n"); Assert.Equal(1, commit2.ParentsCount); Assert.Equal(commit.Id, commit2.Parents.First().Id); Branch firstCommitBranch = repo.CreateBranch("davidfowl-rules", commit); repo.Checkout(firstCommitBranch); File.WriteAllText(filePath, "davidfowl commits!\n"); var author3 = new Signature("David Fowler", "*****@*****.**", author.When.AddSeconds(2)); repo.Index.Stage(relativeFilepath); Commit commit3 = repo.Commit("I'm going to branch you backwards in time!", author3, author3); AssertBlobContent(repo.Head[relativeFilepath], "davidfowl commits!\n"); AssertBlobContent(commit3[relativeFilepath], "davidfowl commits!\n"); Assert.Equal(1, commit3.ParentsCount); Assert.Equal(commit.Id, commit3.Parents.First().Id); AssertBlobContent(firstCommitBranch[relativeFilepath], "nulltoken\n"); } }
protected void VerifyCurrentSignature(Signature expectedSignature) { var currentSignature = Editor.GetCurrentSignature(); Assert.Equal(expectedSignature, currentSignature); }
[System.Security.SecuritySafeCritical] // auto-generated public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) { if ((CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs) throw new NotSupportedException(Environment.GetResourceString("NotSupported_CallToVarArg")); Contract.EndContractBlock(); // // We do not demand any permission here because the caller already has access // to the current DynamicMethod object, and it could just as easily emit another // Transparent DynamicMethod to call the current DynamicMethod. // RuntimeMethodHandle method = GetMethodDescriptor(); // ignore obj since it's a static method // create a signature object Signature sig = new Signature( this.m_methodHandle, m_parameterTypes, m_returnType, CallingConvention); // verify arguments int formalCount = sig.Arguments.Length; int actualCount = (parameters != null) ? parameters.Length : 0; if (formalCount != actualCount) throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt")); // if we are here we passed all the previous checks. Time to look at the arguments Object retValue = null; if (actualCount > 0) { Object[] arguments = CheckArguments(parameters, binder, invokeAttr, culture, sig); retValue = RuntimeMethodHandle.InvokeMethod(null, arguments, sig, false); // copy out. This should be made only if ByRef are present. for (int index = 0; index < arguments.Length; index++) parameters[index] = arguments[index]; } else { retValue = RuntimeMethodHandle.InvokeMethod(null, null, sig, false); } GC.KeepAlive(this); return retValue; }
[System.Security.SecurityCritical] // auto-generated internal unsafe static ParameterInfo[] GetParameters(IRuntimeMethodInfo method, MemberInfo member, Signature sig) { Contract.Assert(method is RuntimeMethodInfo || method is RuntimeConstructorInfo); ParameterInfo dummy; return GetParameters(method, member, sig, out dummy, false); }
internal static extern bool CompareSig(Signature sig1, Signature sig2);
[System.Security.SecurityCritical] // auto-generated internal unsafe static ParameterInfo GetReturnParameter(IRuntimeMethodInfo method, MemberInfo member, Signature sig) { Contract.Assert(method is RuntimeMethodInfo || method is RuntimeConstructorInfo); ParameterInfo returnParameter; GetParameters(method, member, sig, out returnParameter, true); return returnParameter; }