public void TestEncodeAndDecode() { var eid1 = new EntityIdentifier(EntityType.Organization, _testGuid); var eid1Str = eid1.ToString(); var eid2 = EntityIdentifier.FromString(eid1Str); Assert.AreEqual(eid1, eid2); }
/// <summary> /// Returns string interpretation /// </summary> /// <returns></returns> public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append(base.ToString()); sb.AppendLine("Originating Entity Identifier: " + originatingEntityID.ToString()); sb.AppendLine("Receiving Entity Identifier: " + receivingEntityID.ToString()); return(sb.ToString()); }
/// <summary> /// Returns a string representation. /// </summary> /// <returns></returns> public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append(base.ToString()); sb.Append("Firing Identifier: " + firingEntityID.ToString()); sb.Append("Target Identifier: " + targetEntityID.ToString()); sb.Append("Munition Identifier: " + munitionID.ToString()); sb.Append("Event Identifier: " + eventID.ToString()); return(sb.ToString()); }
/// <summary> /// Returns a string representation. /// </summary> /// <returns></returns> public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append(base.ToString()); sb.Append("Issuing EntityID: " + issuingEntityID.ToString()); sb.Append("Colliding EntityID: " + collidingEntityID.ToString()); sb.Append("Event: " + eventID.ToString()); sb.AppendLine("Collision Type: " + collisionType); sb.AppendLine("Velocity: " + velocity.ToString()); sb.AppendFormat("Mass {0}kg\n", mass); sb.AppendLine("Location: " + location.ToString()); return(sb.ToString()); }
/// <summary> /// Returns a string representation. /// </summary> /// <returns></returns> public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append(base.ToString()); sb.Append("Entity Identifier: " + entityID.ToString()); sb.AppendLine("Force: " + forceID); sb.Append(entityType.ToString()); sb.Append(alternateEntityType.ToString()); sb.AppendLine("Linear Velocity: " + linearVelocity.ToString()); sb.AppendLine("World Coordinates: " + location.ToString()); sb.AppendLine("Orientation: " + orientation.ToString()); sb.Append(appearance.ToString()); // TODO: Entity Type specific appearance ToString() sb.Append(deadReckoningParameter.ToString()); sb.Append(marking.ToString()); sb.Append(capabilities.ToString()); sb.Append(variableParameters.ToString()); return(sb.ToString()); }
public void TestServiceToString() { var eid = new EntityIdentifier(EntityType.Service, _testGuid); Assert.AreEqual($"svc:{_testGuidString}", eid.ToString()); }
public void TestOrganizationToString() { var eid = new EntityIdentifier(EntityType.Organization, _testGuid); Assert.AreEqual($"org:{_testGuidString}", eid.ToString()); }
public void TestDirectoryToString() { var eid = new EntityIdentifier(EntityType.Directory, _testGuid); Assert.AreEqual($"dir:{_testGuidString}", eid.ToString()); }
private HttpResponse ExecuteRequest( HttpMethod method, string path, EntityIdentifier subjectEntity, object transportObject, List <int> httpStatusCodeWhiteList) { try { var requestUrl = MakeUrl(path); var requestBody = EncodeRequestBody(transportObject); // encrypt the payload using the API's public key var publicKey = GetCurrentPublicKey(); string hashString = null; string hashFunction = null; string encryptedPayload = null; if (requestBody != null) { encryptedPayload = _jweService.Encrypt( requestBody, publicKey.KeyData, publicKey.Thumbprint, "application/json" ); var hash = _crypto.Sha256(Encoding.UTF8.GetBytes(encryptedPayload)); hashString = ByteArrayUtils.ByteArrayToHexString(hash); hashFunction = "S256"; } var requestId = Guid.NewGuid().ToString("D"); // sign the encrypted payload and turn it into a JWT token ... this is sent as the header var token = _jwtService.Encode( requestId, _issuer.ToString(), subjectEntity.ToString(), GetCurrentTime(), method.ToString(), path, hashFunction, hashString ); var response = _httpClient.ExecuteRequest( method, requestUrl, encryptedPayload, new Dictionary <string, string> { { "Authorization", "IOV-JWT " + token } } ); var JWTHeaders = Jose.JWT.Headers(response.Headers[IOV_JWT_HEADER]); string kid = (string)JWTHeaders["kid"]; if (kid != publicKey.Thumbprint) { publicKey = FetchPublicKeyWithId(kid); } // check for errors, decode and decrypt them if needed and crash out ThrowForStatus(response, publicKey.KeyData, requestId, httpStatusCodeWhiteList); // validate the response itself ValidateEncryptedResponse(response, publicKey.KeyData, requestId); // if we're here, we've passed all validation and error handling return(response); } catch (JwtError ex) { throw new InvalidResponseException("JWT error occurred -- see exception", ex); } catch (IOException ex) { throw new CommunicationErrorException("A network-level error occurred, see inner exception.", ex); } catch (TimeoutException ex) { throw new CommunicationErrorException("A connection timeout occurred, see inner exception.", ex); } }