use of org.eclipse.titan.designer.AST.ASN1.ASN1Object in project android_frameworks_base by AOSPA.
the class ESTHandler method execute.
public void execute(boolean reenroll) throws IOException, GeneralSecurityException {
URL caURL = new URL(mURL.getProtocol(), mURL.getHost(), mURL.getPort(), mURL.getFile() + CACERT_PATH);
HTTPResponse response;
try (HTTPHandler httpHandler = new HTTPHandler(StandardCharsets.ISO_8859_1, mSocketFactory, mUser, mPassword)) {
response = httpHandler.doGetHTTP(caURL);
if (!"application/pkcs7-mime".equals(response.getHeaders().get(HTTPMessage.ContentTypeHeader))) {
throw new IOException("Unexpected Content-Type: " + response.getHeaders().get(HTTPMessage.ContentTypeHeader));
}
ByteBuffer octetBuffer = response.getBinaryPayload();
Collection<Asn1Object> pkcs7Content1 = Asn1Decoder.decode(octetBuffer);
for (Asn1Object asn1Object : pkcs7Content1) {
Log.d(TAG, "---");
Log.d(TAG, asn1Object.toString());
}
Log.d(TAG, CACERT_PATH);
mCACerts.addAll(unpackPkcs7(octetBuffer));
for (X509Certificate certificate : mCACerts) {
Log.d(TAG, "CA-Cert: " + certificate.getSubjectX500Principal());
}
/*
byte[] octets = new byte[octetBuffer.remaining()];
octetBuffer.duplicate().get(octets);
for (byte b : octets) {
System.out.printf("%02x ", b & 0xff);
}
Log.d(TAG, );
*/
/* + BC
try {
byte[] octets = new byte[octetBuffer.remaining()];
octetBuffer.duplicate().get(octets);
ASN1InputStream asnin = new ASN1InputStream(octets);
for (int n = 0; n < 100; n++) {
ASN1Primitive object = asnin.readObject();
if (object == null) {
break;
}
parseObject(object, 0);
}
}
catch (Throwable t) {
t.printStackTrace();
}
Collection<Asn1Object> pkcs7Content = Asn1Decoder.decode(octetBuffer);
for (Asn1Object asn1Object : pkcs7Content) {
Log.d(TAG, asn1Object);
}
if (pkcs7Content.size() != 1) {
throw new IOException("Unexpected pkcs 7 container: " + pkcs7Content.size());
}
Asn1Constructed pkcs7Root = (Asn1Constructed) pkcs7Content.iterator().next();
Iterator<Asn1ID> certPath = Arrays.asList(Pkcs7CertPath).iterator();
Asn1Object certObject = pkcs7Root.findObject(certPath);
if (certObject == null || certPath.hasNext()) {
throw new IOException("Failed to find cert; returned object " + certObject +
", path " + (certPath.hasNext() ? "short" : "exhausted"));
}
ByteBuffer certOctets = certObject.getPayload();
if (certOctets == null) {
throw new IOException("No cert payload in: " + certObject);
}
byte[] certBytes = new byte[certOctets.remaining()];
certOctets.get(certBytes);
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
Certificate cert = certFactory.generateCertificate(new ByteArrayInputStream(certBytes));
Log.d(TAG, "EST Cert: " + cert);
*/
URL csrURL = new URL(mURL.getProtocol(), mURL.getHost(), mURL.getPort(), mURL.getFile() + CSR_PATH);
response = httpHandler.doGetHTTP(csrURL);
octetBuffer = response.getBinaryPayload();
byte[] csrData = buildCSR(octetBuffer, mOMADMAdapter, httpHandler);
/**/
Collection<Asn1Object> o = Asn1Decoder.decode(ByteBuffer.wrap(csrData));
Log.d(TAG, "CSR:");
Log.d(TAG, o.iterator().next().toString());
Log.d(TAG, "End CSR.");
/**/
URL enrollURL = new URL(mURL.getProtocol(), mURL.getHost(), mURL.getPort(), mURL.getFile() + (reenroll ? SIMPLE_REENROLL_PATH : SIMPLE_ENROLL_PATH));
String data = Base64.encodeToString(csrData, Base64.DEFAULT);
octetBuffer = httpHandler.exchangeBinary(enrollURL, data, "application/pkcs10");
Collection<Asn1Object> pkcs7Content2 = Asn1Decoder.decode(octetBuffer);
for (Asn1Object asn1Object : pkcs7Content2) {
Log.d(TAG, "---");
Log.d(TAG, asn1Object.toString());
}
mClientCerts.addAll(unpackPkcs7(octetBuffer));
for (X509Certificate cert : mClientCerts) {
Log.d(TAG, cert.toString());
}
}
}
use of org.eclipse.titan.designer.AST.ASN1.ASN1Object in project android_frameworks_base by AOSPA.
the class ESTHandler method unpackPkcs7.
private static List<X509Certificate> unpackPkcs7(ByteBuffer pkcs7) throws IOException, GeneralSecurityException {
Collection<Asn1Object> pkcs7Content = Asn1Decoder.decode(pkcs7);
if (pkcs7Content.size() != 1) {
throw new IOException("Unexpected pkcs 7 container: " + pkcs7Content.size());
}
Asn1Object data = pkcs7Content.iterator().next();
if (!data.isConstructed() || !data.matches(sSEQUENCE)) {
throw new IOException("Expected SEQ OF, got " + data.toSimpleString());
} else if (data.getChildren().size() != 2) {
throw new IOException("Expected content info to have two children, got " + data.getChildren().size());
}
Iterator<Asn1Object> children = data.getChildren().iterator();
Asn1Object contentType = children.next();
if (!contentType.equals(Asn1Oid.PKCS7SignedData)) {
throw new IOException("Content not PKCS7 signed data");
}
Asn1Object content = children.next();
if (!content.isConstructed() || !content.matches(sCTXT0)) {
throw new IOException("Expected [CONTEXT 0] with one child, got " + content.toSimpleString() + ", " + content.getChildren().size());
}
Asn1Object signedData = content.getChildren().iterator().next();
Map<Integer, Asn1Object> itemMap = new HashMap<>();
for (Asn1Object item : signedData.getChildren()) {
if (itemMap.put(item.getTag(), item) != null && item.getTag() != Asn1Decoder.TAG_SET) {
throw new IOException("Duplicate item in SignedData: " + item.toSimpleString());
}
}
Asn1Object versionObject = itemMap.get(Asn1Decoder.TAG_INTEGER);
if (versionObject == null || !(versionObject instanceof Asn1Integer)) {
throw new IOException("Bad or missing PKCS7 version: " + versionObject);
}
int pkcs7version = (int) ((Asn1Integer) versionObject).getValue();
Asn1Object innerContentInfo = itemMap.get(Asn1Decoder.TAG_SEQ);
if (innerContentInfo == null || !innerContentInfo.isConstructed() || !innerContentInfo.matches(sSEQUENCE) || innerContentInfo.getChildren().size() != 1) {
throw new IOException("Bad or missing PKCS7 contentInfo");
}
Asn1Object contentID = innerContentInfo.getChildren().iterator().next();
if (pkcs7version == PKCS7DataVersion && !contentID.equals(Asn1Oid.PKCS7Data) || pkcs7version == PKCS7SignedDataVersion && !contentID.equals(Asn1Oid.PKCS7SignedData)) {
throw new IOException("Inner PKCS7 content (" + contentID + ") not expected for version " + pkcs7version);
}
Asn1Object certWrapper = itemMap.get(0);
if (certWrapper == null || !certWrapper.isConstructed() || !certWrapper.matches(sCTXT0)) {
throw new IOException("Expected [CONTEXT 0], got: " + certWrapper);
}
List<X509Certificate> certList = new ArrayList<>(certWrapper.getChildren().size());
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
for (Asn1Object certObject : certWrapper.getChildren()) {
ByteBuffer certOctets = ((Asn1Constructed) certObject).getEncoding();
if (certOctets == null) {
throw new IOException("No cert payload in: " + certObject);
}
byte[] certBytes = new byte[certOctets.remaining()];
certOctets.get(certBytes);
certList.add((X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(certBytes)));
}
return certList;
}
use of org.eclipse.titan.designer.AST.ASN1.ASN1Object in project xipki by xipki.
the class P11ProxyResponder method processRequest.
/**
* The request is constructed as follows:
* <pre>
* 0 - - - 1 - - - 2 - - - 3 - - - 4 - - - 5 - - - 6 - - - 7 - - - 8
* | Version | Transaction ID | Body ... |
* | ... Length | Action | Module ID | Content... |
* | .Content | <-- 10 + Length (offset).
*
* </pre>
*/
byte[] processRequest(LocalP11CryptServicePool pool, byte[] request) {
int reqLen = request.length;
// TransactionID
byte[] transactionId = new byte[4];
if (reqLen > 5) {
System.arraycopy(request, 2, transactionId, 0, 4);
}
// Action
short action = P11ProxyConstants.ACTION_NOPE;
if (reqLen > 11) {
action = IoUtil.parseShort(request, 10);
}
if (reqLen < 14) {
LOG.error("response too short");
return getResp(P11ProxyConstants.VERSION_V1_0, transactionId, action, P11ProxyConstants.RC_BAD_REQUEST);
}
// Version
short version = IoUtil.parseShort(request, 0);
if (!versions.contains(version)) {
LOG.error("unsupported version {}", version);
return getResp(P11ProxyConstants.VERSION_V1_0, transactionId, action, P11ProxyConstants.RC_UNSUPPORTED_VERSION);
}
// Length
int reqBodyLen = IoUtil.parseInt(request, 6);
if (reqBodyLen + 10 != reqLen) {
LOG.error("message length unmatch");
return getResp(version, transactionId, action, P11ProxyConstants.RC_BAD_REQUEST);
}
short moduleId = IoUtil.parseShort(request, 12);
int contentLen = reqLen - 14;
byte[] content;
if (contentLen == 0) {
if (actionsRequireNonNullRequest.contains(action)) {
LOG.error("content is not present but is required");
return getResp(version, transactionId, P11ProxyConstants.RC_BAD_REQUEST, action);
}
content = null;
} else {
if (actionsRequireNullRequest.contains(action)) {
LOG.error("content is present but is not permitted");
return getResp(version, transactionId, P11ProxyConstants.RC_BAD_REQUEST, action);
}
content = new byte[contentLen];
System.arraycopy(request, 14, content, 0, contentLen);
}
P11CryptService p11CryptService = pool.getP11CryptService(moduleId);
if (p11CryptService == null) {
LOG.error("no module {} available", moduleId);
return getResp(version, transactionId, P11ProxyConstants.RC_UNKNOWN_MODULE, action);
}
try {
switch(action) {
case P11ProxyConstants.ACTION_ADD_CERT:
{
Asn1EntityIdAndCert asn1 = Asn1EntityIdAndCert.getInstance(content);
P11Slot slot = getSlot(p11CryptService, asn1.getEntityId());
X509Certificate cert = X509Util.toX509Cert(asn1.getCertificate());
slot.addCert(asn1.getEntityId().getObjectId().getObjectId(), cert);
return getSuccessResp(version, transactionId, action, (byte[]) null);
}
case P11ProxyConstants.ACTION_DIGEST_SECRETKEY:
{
Asn1DigestSecretKeyTemplate template = Asn1DigestSecretKeyTemplate.getInstance(content);
long mechanism = template.getMechanism().getMechanism();
P11Identity identity = p11CryptService.getIdentity(template.getIdentityId().getEntityId());
byte[] hashValue = identity.digestSecretKey(mechanism);
ASN1Object obj = new DEROctetString(hashValue);
return getSuccessResp(version, transactionId, action, obj);
}
case P11ProxyConstants.ACTION_GEN_KEYPAIR_DSA:
{
Asn1GenDSAKeypairParams asn1 = Asn1GenDSAKeypairParams.getInstance(content);
P11Slot slot = getSlot(p11CryptService, asn1.getSlotId());
P11ObjectIdentifier keyId = slot.generateDSAKeypair(asn1.getP(), asn1.getQ(), asn1.getG(), asn1.getLabel(), asn1.getControl());
ASN1Object obj = new Asn1P11EntityIdentifier(asn1.getSlotId(), keyId);
return getSuccessResp(version, transactionId, action, obj);
}
case P11ProxyConstants.ACTION_GEN_KEYPAIR_EC:
{
Asn1GenECKeypairParams asn1 = Asn1GenECKeypairParams.getInstance(content);
P11Slot slot = getSlot(p11CryptService, asn1.getSlotId());
P11ObjectIdentifier keyId = slot.generateECKeypair(asn1.getCurveId().getId(), asn1.getLabel(), asn1.getControl());
ASN1Object obj = new Asn1P11EntityIdentifier(asn1.getSlotId(), keyId);
return getSuccessResp(version, transactionId, action, obj);
}
case P11ProxyConstants.ACTION_GEN_KEYPAIR_RSA:
{
Asn1GenRSAKeypairParams asn1 = Asn1GenRSAKeypairParams.getInstance(content);
P11Slot slot = getSlot(p11CryptService, asn1.getSlotId());
P11ObjectIdentifier keyId = slot.generateRSAKeypair(asn1.getKeysize(), asn1.getPublicExponent(), asn1.getLabel(), asn1.getControl());
ASN1Object obj = new Asn1P11EntityIdentifier(asn1.getSlotId(), keyId);
return getSuccessResp(version, transactionId, action, obj);
}
case P11ProxyConstants.ACTION_GEN_KEYPAIR_SM2:
{
Asn1GenSM2KeypairParams asn1 = Asn1GenSM2KeypairParams.getInstance(content);
P11Slot slot = getSlot(p11CryptService, asn1.getSlotId());
P11ObjectIdentifier keyId = slot.generateSM2Keypair(asn1.getLabel(), asn1.getControl());
ASN1Object obj = new Asn1P11EntityIdentifier(asn1.getSlotId(), keyId);
return getSuccessResp(version, transactionId, action, obj);
}
case P11ProxyConstants.ACTION_GEN_SECRET_KEY:
{
Asn1GenSecretKeyParams asn1 = Asn1GenSecretKeyParams.getInstance(content);
P11Slot slot = getSlot(p11CryptService, asn1.getSlotId());
P11ObjectIdentifier keyId = slot.generateSecretKey(asn1.getKeyType(), asn1.getKeysize(), asn1.getLabel(), asn1.getControl());
ASN1Object obj = new Asn1P11EntityIdentifier(asn1.getSlotId(), keyId);
return getSuccessResp(version, transactionId, action, obj);
}
case P11ProxyConstants.ACTION_GET_CERT:
{
P11EntityIdentifier entityId = Asn1P11EntityIdentifier.getInstance(content).getEntityId();
X509Certificate cert = p11CryptService.getIdentity(entityId).getCertificate();
return getSuccessResp(version, transactionId, action, cert.getEncoded());
}
case P11ProxyConstants.ACTION_GET_CERT_IDS:
case P11ProxyConstants.ACTION_GET_IDENTITY_IDS:
{
Asn1P11SlotIdentifier slotId = Asn1P11SlotIdentifier.getInstance(content);
P11Slot slot = p11CryptService.getModule().getSlot(slotId.getSlotId());
Set<P11ObjectIdentifier> objectIds;
if (P11ProxyConstants.ACTION_GET_CERT_IDS == action) {
objectIds = slot.getCertIdentifiers();
} else {
objectIds = slot.getIdentityIdentifiers();
}
ASN1EncodableVector vec = new ASN1EncodableVector();
for (P11ObjectIdentifier objectId : objectIds) {
vec.add(new Asn1P11ObjectIdentifier(objectId));
}
ASN1Object obj = new DERSequence(vec);
return getSuccessResp(version, transactionId, action, obj);
}
case P11ProxyConstants.ACTION_GET_MECHANISMS:
{
P11SlotIdentifier slotId = Asn1P11SlotIdentifier.getInstance(content).getSlotId();
Set<Long> mechs = p11CryptService.getSlot(slotId).getMechanisms();
ASN1EncodableVector vec = new ASN1EncodableVector();
for (Long mech : mechs) {
vec.add(new ASN1Integer(mech));
}
ASN1Object obj = new DERSequence(vec);
return getSuccessResp(version, transactionId, action, obj);
}
case P11ProxyConstants.ACTION_GET_PUBLICKEY:
{
P11EntityIdentifier identityId = Asn1P11EntityIdentifier.getInstance(content).getEntityId();
PublicKey pubKey = p11CryptService.getIdentity(identityId).getPublicKey();
if (pubKey == null) {
throw new P11UnknownEntityException(identityId);
}
ASN1Object obj = KeyUtil.createSubjectPublicKeyInfo(pubKey);
return getSuccessResp(version, transactionId, action, obj);
}
case P11ProxyConstants.ACTION_GET_SERVER_CAPS:
{
boolean readOnly = p11CryptService.getModule().isReadOnly();
ASN1Object obj = new Asn1ServerCaps(readOnly, versions);
return getSuccessResp(version, transactionId, action, obj);
}
case P11ProxyConstants.ACTION_GET_SLOT_IDS:
{
List<P11SlotIdentifier> slotIds = p11CryptService.getModule().getSlotIds();
ASN1EncodableVector vector = new ASN1EncodableVector();
for (P11SlotIdentifier slotId : slotIds) {
vector.add(new Asn1P11SlotIdentifier(slotId));
}
ASN1Object obj = new DERSequence(vector);
return getSuccessResp(version, transactionId, action, obj);
}
case P11ProxyConstants.ACTION_IMPORT_SECRET_KEY:
{
Asn1ImportSecretKeyParams asn1 = Asn1ImportSecretKeyParams.getInstance(content);
P11Slot slot = getSlot(p11CryptService, asn1.getSlotId());
P11ObjectIdentifier keyId = slot.importSecretKey(asn1.getKeyType(), asn1.getKeyValue(), asn1.getLabel(), asn1.getControl());
ASN1Object obj = new Asn1P11EntityIdentifier(asn1.getSlotId(), keyId);
return getSuccessResp(version, transactionId, action, obj);
}
case P11ProxyConstants.ACTION_REMOVE_CERTS:
{
Asn1P11EntityIdentifier asn1 = Asn1P11EntityIdentifier.getInstance(content);
P11Slot slot = getSlot(p11CryptService, asn1);
slot.removeCerts(asn1.getObjectId().getObjectId());
return getSuccessResp(version, transactionId, action, (byte[]) null);
}
case P11ProxyConstants.ACTION_REMOVE_IDENTITY:
{
Asn1P11EntityIdentifier asn1 = Asn1P11EntityIdentifier.getInstance(content);
P11Slot slot = getSlot(p11CryptService, asn1);
slot.removeIdentity(asn1.getObjectId().getObjectId());
return getSuccessResp(version, transactionId, action, (byte[]) null);
}
case P11ProxyConstants.ACTION_REMOVE_OBJECTS:
{
Asn1RemoveObjectsParams asn1 = Asn1RemoveObjectsParams.getInstance(content);
P11Slot slot = getSlot(p11CryptService, asn1.getSlotId());
int num = slot.removeObjects(asn1.getOjectId(), asn1.getObjectLabel());
ASN1Object obj = new ASN1Integer(num);
return getSuccessResp(version, transactionId, action, obj);
}
case P11ProxyConstants.ACTION_SIGN:
{
Asn1SignTemplate signTemplate = Asn1SignTemplate.getInstance(content);
long mechanism = signTemplate.getMechanism().getMechanism();
Asn1P11Params asn1Params = signTemplate.getMechanism().getParams();
P11Params params = null;
if (asn1Params != null) {
switch(asn1Params.getTagNo()) {
case Asn1P11Params.TAG_RSA_PKCS_PSS:
params = Asn1RSAPkcsPssParams.getInstance(asn1Params).getPkcsPssParams();
break;
case Asn1P11Params.TAG_OPAQUE:
params = new P11ByteArrayParams(ASN1OctetString.getInstance(asn1Params).getOctets());
break;
case Asn1P11Params.TAG_IV:
params = new P11IVParams(ASN1OctetString.getInstance(asn1Params).getOctets());
break;
default:
throw new BadAsn1ObjectException("unknown SignTemplate.params: unknown tag " + asn1Params.getTagNo());
}
}
byte[] message = signTemplate.getMessage();
P11Identity identity = p11CryptService.getIdentity(signTemplate.getIdentityId().getEntityId());
byte[] signature = identity.sign(mechanism, params, message);
ASN1Object obj = new DEROctetString(signature);
return getSuccessResp(version, transactionId, action, obj);
}
case P11ProxyConstants.ACTION_UPDATE_CERT:
{
Asn1EntityIdAndCert asn1 = Asn1EntityIdAndCert.getInstance(content);
P11Slot slot = getSlot(p11CryptService, asn1.getEntityId());
slot.updateCertificate(asn1.getEntityId().getObjectId().getObjectId(), X509Util.toX509Cert(asn1.getCertificate()));
return getSuccessResp(version, transactionId, action, (byte[]) null);
}
default:
{
LOG.error("unsupported XiPKI action code '{}'", action);
return getResp(version, transactionId, action, P11ProxyConstants.RC_UNSUPPORTED_ACTION);
}
}
} catch (BadAsn1ObjectException ex) {
LogUtil.error(LOG, ex, "could not process decode requested content (tid=" + Hex.encode(transactionId) + ")");
return getResp(version, transactionId, action, P11ProxyConstants.RC_BAD_REQUEST);
} catch (P11TokenException ex) {
LogUtil.error(LOG, ex, buildErrorMsg(action, transactionId));
short rc;
if (ex instanceof P11UnknownEntityException) {
rc = P11ProxyConstants.RC_DUPLICATE_ENTITY;
} else if (ex instanceof P11DuplicateEntityException) {
rc = P11ProxyConstants.RC_DUPLICATE_ENTITY;
} else if (ex instanceof P11UnsupportedMechanismException) {
rc = P11ProxyConstants.RC_UNSUPPORTED_MECHANISM;
} else {
rc = P11ProxyConstants.RC_P11_TOKENERROR;
}
return getResp(version, transactionId, action, rc);
} catch (XiSecurityException | CertificateException | InvalidKeyException ex) {
LogUtil.error(LOG, ex, buildErrorMsg(action, transactionId));
return getResp(version, transactionId, action, P11ProxyConstants.RC_INTERNAL_ERROR);
} catch (Throwable th) {
LogUtil.error(LOG, th, buildErrorMsg(action, transactionId));
return getResp(version, transactionId, action, P11ProxyConstants.RC_INTERNAL_ERROR);
}
}
use of org.eclipse.titan.designer.AST.ASN1.ASN1Object in project titan.EclipsePlug-ins by eclipse.
the class InformationFromObj method getRefdSetting.
@Override
public /**
* {@inheritDoc}
*/
ISetting getRefdSetting(final CompilationTimeStamp timestamp) {
setIsErroneous(false);
ISetting temporalSetting = reference.getRefdSetting(timestamp);
if (null == temporalSetting) {
setIsErroneous(true);
return new Error_Setting();
}
SettingDetectionState currentState;
ObjectClass_Definition objectClass = null;
ObjectSet_definition objectSet = null;
Object_Definition object = null;
object = new Object_Definition(null);
ObjectSet_definition fromObjectSet = newObjectSetDefinitionInstance();
/* the first part */
switch(temporalSetting.getSettingtype()) {
case S_OS:
currentState = SettingDetectionState.ObjectSet;
objectSet = ((ObjectSet) temporalSetting).getRefdLast(timestamp, null);
objectClass = objectSet.getMyGovernor().getRefdLast(timestamp, null);
final ObjectSetElementVisitor_objectCollector objectCollector = new ObjectSetElementVisitor_objectCollector(objectSet.getLocation(), objectClass, timestamp);
objectCollector.visitObjectSet(objectSet, false);
fromObjectSet = newObjectSetDefinitionInstance(objectCollector.giveObjects());
fromObjectSet.setMyGovernor(objectClass);
break;
case S_O:
currentState = SettingDetectionState.Object;
object = ((ASN1Object) temporalSetting).getRefdLast(timestamp, null);
objectClass = object.getMyGovernor().getRefdLast(timestamp, null);
break;
case S_OC:
currentState = SettingDetectionState.ObjectClass;
objectClass = ((ObjectClass) temporalSetting).getRefdLast(timestamp, null);
break;
case S_ERROR:
setIsErroneous(true);
return new Error_Setting();
default:
location.reportSemanticError(MessageFormat.format(INVALIDREFERENCE, getDisplayName()));
setIsErroneous(true);
return new Error_Setting();
}
final int nofFields = fieldName.getNofFields();
/* the middle part */
Identifier currentFieldName;
FieldSpecification currentFieldSpecification;
for (int i = 0; i < nofFields - 1; i++) {
currentFieldName = fieldName.getFieldByIndex(i);
currentFieldSpecification = objectClass.getFieldSpecifications().getFieldSpecificationByIdentifier(currentFieldName).getLast();
if (Fieldspecification_types.FS_ERROR.equals(currentFieldSpecification.getFieldSpecificationType())) {
setIsErroneous(true);
return new Error_Setting();
}
switch(currentState) {
case ObjectClass:
switch(currentFieldSpecification.getFieldSpecificationType()) {
case FS_O:
{
final Object_FieldSpecification temporalFieldspec = (Object_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
}
break;
case FS_OS:
{
final ObjectSet_FieldSpecification temporalFieldspec = (ObjectSet_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
}
break;
case FS_ERROR:
setIsErroneous(true);
return new Error_Setting();
default:
location.reportSemanticError(INVALIDNOTATION1);
setIsErroneous(true);
return new Error_Setting();
}
break;
case ObjectSet:
switch(currentFieldSpecification.getFieldSpecificationType()) {
case FS_O:
{
final Object_FieldSpecification temporalFieldspec = (Object_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
final ObjectSetElementVisitor_objectCollector objectCollector = new ObjectSetElementVisitor_objectCollector(location, objectClass, timestamp);
final ASN1Objects temporalObjects = fromObjectSet.getObjs();
temporalObjects.trimToSize();
for (int j = 0; j < temporalObjects.getNofObjects(); j++) {
object = temporalObjects.getObjectByIndex(j).getRefdLast(timestamp, null);
if (!object.hasFieldSettingWithNameDefault(currentFieldName)) {
continue;
}
temporalSetting = object.getSettingByNameDefault(currentFieldName);
object = ((Object_Definition) temporalSetting).getRefdLast(timestamp, null);
objectCollector.visitObject(object);
}
fromObjectSet = newObjectSetDefinitionInstance(objectCollector.giveObjects());
fromObjectSet.setLocation(location);
fromObjectSet.setMyGovernor(objectClass);
}
break;
case FS_OS:
{
final ObjectSet_FieldSpecification temporalFieldspec = (ObjectSet_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
final ObjectSetElementVisitor_objectCollector objectCollector2 = new ObjectSetElementVisitor_objectCollector(location, objectClass, timestamp);
final ASN1Objects temporalObjects = fromObjectSet.getObjs();
for (int j = 0; j < temporalObjects.getNofObjects(); j++) {
object = temporalObjects.getObjectByIndex(j).getRefdLast(timestamp, null);
if (!object.hasFieldSettingWithNameDefault(currentFieldName)) {
continue;
}
temporalSetting = object.getSettingByNameDefault(currentFieldName);
objectSet = ((ObjectSet_definition) temporalSetting).getRefdLast(timestamp, null);
objectCollector2.visitObjectSet(objectSet, false);
}
fromObjectSet = newObjectSetDefinitionInstance(objectCollector2.giveObjects());
fromObjectSet.setLocation(location);
fromObjectSet.setMyGovernor(objectClass);
}
break;
case FS_ERROR:
setIsErroneous(true);
return new Error_Setting();
default:
location.reportSemanticError(INVALIDNOTATION1);
setIsErroneous(true);
return new Error_Setting();
}
break;
case Object:
switch(currentFieldSpecification.getFieldSpecificationType()) {
case FS_O:
{
final Object_FieldSpecification temporalFieldspec = (Object_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
temporalSetting = object.getSettingByNameDefault(currentFieldName);
object = ((Object_Definition) temporalSetting).getRefdLast(timestamp, null);
}
break;
case FS_OS:
{
currentState = SettingDetectionState.ObjectSet;
final ObjectSet_FieldSpecification temporalFieldspec = (ObjectSet_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
final ObjectSetElementVisitor_objectCollector objectCollector = new ObjectSetElementVisitor_objectCollector(fromObjectSet, timestamp);
final ASN1Objects temporalObjects = fromObjectSet.getObjs();
for (int j = 0; j < temporalObjects.getNofObjects(); j++) {
object = temporalObjects.getObjectByIndex(j).getRefdLast(timestamp, null);
if (!object.hasFieldSettingWithNameDefault(currentFieldName)) {
continue;
}
temporalSetting = object.getSettingByNameDefault(currentFieldName);
objectSet = ((ObjectSet_definition) temporalSetting).getRefdLast(timestamp, null);
objectCollector.visitObjectSet(objectSet, false);
}
fromObjectSet = newObjectSetDefinitionInstance(objectCollector.giveObjects());
fromObjectSet.setLocation(location);
fromObjectSet.setMyGovernor(objectClass);
}
break;
case FS_ERROR:
setIsErroneous(true);
return new Error_Setting();
default:
location.reportSemanticError(INVALIDNOTATION1);
setIsErroneous(true);
return new Error_Setting();
}
break;
default:
// if this could happen it would be FATAL ERROR
break;
}
}
/* and the last part... */
currentFieldName = fieldName.getFieldByIndex(nofFields - 1);
currentFieldSpecification = objectClass.getFieldSpecifications().getFieldSpecificationByIdentifier(currentFieldName).getLast();
temporalSetting = null;
switch(currentState) {
case ObjectClass:
switch(currentFieldSpecification.getFieldSpecificationType()) {
case FS_T:
{
final Open_Type type = new Open_Type(objectClass, currentFieldName);
type.setLocation(location);
type.setMyScope(myScope);
temporalSetting = type;
}
break;
case FS_V_FT:
{
final FixedTypeValue_FieldSpecification temporalFielspecification = (FixedTypeValue_FieldSpecification) currentFieldSpecification;
final ObjectClassField_Type type = new ObjectClassField_Type(temporalFielspecification.getType(), objectClass, currentFieldName);
type.setLocation(location);
temporalSetting = type;
}
break;
case FS_V_VT:
case FS_VS_FT:
case FS_VS_VT:
location.reportSemanticError(UNSUPPORTEDCONSTRUCT);
setIsErroneous(true);
break;
case FS_O:
case FS_OS:
location.reportSemanticError(INVALIDNOTATION2);
setIsErroneous(true);
break;
default:
setIsErroneous(true);
break;
}
break;
case ObjectSet:
switch(currentFieldSpecification.getFieldSpecificationType()) {
case FS_O:
{
final Object_FieldSpecification temporalFieldspec = (Object_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
final ObjectSetElementVisitor_objectCollector objectCollector = new ObjectSetElementVisitor_objectCollector(location, objectClass, timestamp);
final ASN1Objects temporalObjects = fromObjectSet.getObjs();
for (int j = 0; j < temporalObjects.getNofObjects(); j++) {
object = temporalObjects.getObjectByIndex(j).getRefdLast(timestamp, null);
if (!object.hasFieldSettingWithNameDefault(currentFieldName)) {
continue;
}
temporalSetting = object.getSettingByNameDefault(currentFieldName);
object = ((Object_Definition) temporalSetting).getRefdLast(timestamp, null);
objectCollector.visitObject(object);
}
fromObjectSet = newObjectSetDefinitionInstance(objectCollector.giveObjects());
fromObjectSet.setLocation(location);
fromObjectSet.setMyGovernor(objectClass);
fromObjectSet.setMyScope(myScope);
temporalSetting = fromObjectSet;
}
break;
case FS_OS:
{
final ObjectSet_FieldSpecification temporalFieldspec = (ObjectSet_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
final ObjectSetElementVisitor_objectCollector objectCollector2 = new ObjectSetElementVisitor_objectCollector(location, objectClass, timestamp);
final ASN1Objects temporalObjects = fromObjectSet.getObjs();
for (int j = 0; j < temporalObjects.getNofObjects(); j++) {
object = temporalObjects.getObjectByIndex(j).getRefdLast(timestamp, null);
if (!object.hasFieldSettingWithNameDefault(currentFieldName)) {
continue;
}
temporalSetting = object.getSettingByNameDefault(currentFieldName);
objectSet = ((ObjectSet_definition) temporalSetting).getRefdLast(timestamp, null);
objectCollector2.visitObjectSet(objectSet, false);
}
fromObjectSet = newObjectSetDefinitionInstance(objectCollector2.giveObjects());
fromObjectSet.setLocation(location);
fromObjectSet.setMyGovernor(objectClass);
fromObjectSet.setMyScope(myScope);
temporalSetting = fromObjectSet;
}
break;
case FS_V_FT:
case FS_VS_FT:
location.reportSemanticError(VALUESETFROMOBJECTS_NOT_SUPPORTED);
setIsErroneous(true);
break;
case FS_ERROR:
setIsErroneous(true);
break;
default:
location.reportSemanticError(INVALIDNOTATION3);
setIsErroneous(true);
break;
}
break;
case Object:
temporalSetting = object.getSettingByNameDefault(currentFieldName);
break;
default:
setIsErroneous(true);
break;
}
return temporalSetting;
}
use of org.eclipse.titan.designer.AST.ASN1.ASN1Object in project titan.EclipsePlug-ins by eclipse.
the class ObjectClassSyntax_Parser method visitSetting.
@Override
public /**
* {@inheritDoc}
*/
void visitSetting(final ObjectClassSyntax_setting parameter) {
FieldSetting fieldSetting = null;
switch(parameter.getSettingType()) {
case S_T:
final ASN1Type type = parseType();
if (null != type) {
fieldSetting = new FieldSetting_Type(parameter.getIdentifier().newInstance(), type);
fieldSetting.setLocation(mBlock.getLocation());
}
break;
case S_V:
final boolean parseSuccess = parseValue();
if (parseSuccess) {
fieldSetting = new FieldSetting_Value(parameter.getIdentifier().newInstance());
fieldSetting.setLocation(mBlock.getLocation());
}
break;
case S_VS:
// TODO mark as NOT SUPPORTED
break;
case S_O:
final ASN1Object object = parseObject();
if (null != object) {
fieldSetting = new FieldSetting_Object(parameter.getIdentifier().newInstance(), object);
fieldSetting.setLocation(mBlock.getLocation());
}
break;
case S_OS:
final ObjectSet objectSet = parseObjectSet();
if (null != objectSet) {
fieldSetting = new FieldSetting_ObjectSet(parameter.getIdentifier().newInstance(), objectSet);
fieldSetting.setLocation(mBlock.getLocation());
}
break;
case S_UNDEF:
// FATAL ERROR
default:
break;
}
previousSuccess = null != fieldSetting;
myObject.addFieldSetting(fieldSetting);
}
Aggregations