Coder Social home page Coder Social logo

asn1editor's Introduction

Build Coverage Status Maintainability Documentation Status

asn1editor

Python based ASN.1 editor

This project contains a generic editor to view and edit ASN.1 encoded data. It can load and save data encoded in various ASN.1 formats. It uses asn1tools to parse ASN.1 specifications and read and write encoded data.

The controller part of the editor is written independently of the used GUI framework. A view implementation with wxPython is provided.

Screenshot

Usage

To start the wxPython based editor, install asn1editor via pip:

pip install asn1editor

Then you can run asn1editor from the shell

asn1editor [-h] [-type TYPE] [-data DATA] [asn1spec]

The ASN.1 specification to be loaded can be passed as an (optional) argument. The type inside the ASN.1 specification can be selected using the syntax < Module name >.< Type name >. Finally, a data file can be passed as well that contains data encoded in the ASN.1 specification.

Features

Supported types

The editor supports a large variety of ASN.1 data types:

  • INTEGER
  • REAL
  • ENUMERATED
  • BOOLEAN
  • OCTET STRING, VisibleString, UTF8String, GeneralString, IA5String, OBJECT IDENTIFIER
  • BIT STRING
  • SEQUENCE, SET
  • SEQUENCE OF, SET OF
  • CHOICE
  • DATE, TIME-OF-DAY, DATE-TIME, GeneralizedTime, UTCTime

Supported encodings

The following encodings are supported for reading and writing data:

  • JER
  • OER
  • XER
  • DER
  • BER
  • PER
  • UPER

GUI features

  • Load and save encoded data
  • View the data in a tree view or as groups

Screenshot

  • See limits of numeric values and texts as tooltips
  • Edit octet strings as ASCII or hex
  • List of recently opened specifications for quick access

IMPORTS

IMPORT references are automatically resolved if the ASN1 files containing the imported types reside in the same directory and have the extension ".asn".

Extending asn1editor

If you want to extend asn1editor with custom functionality, you can pass a plugin object to the WxPythonMainWindow object. The plugin object needs to inherit from asn1editor.Plugin.

Example:

import wx
from asn1editor import WxPythonMainWindow, Plugin

class MyPlugin(Plugin):
    # Implementation of abstract functions goes here
    pass

app = wx.App()

frame = WxPythonMainWindow([MyPlugin()])

frame.Show()

app.MainLoop()

Plugin interface

In order to use custom data formats or to work with the data, plugins can be used. These plugins need to inherit from the Plugin.Plugin class and can use the PluginInterface.PluginInterface class to interact with the main application. A list of plugins can be passed to the constructor of the main editor class and is then automatically embedded in the application.

An example application is if a custom header is added to an ASN.1 encoded data. Then the plugin can decode the header, choose the appropriate ASN.1 specification, load it, decode the data and display it.

Type augmenter

The editor can be customized to modify the display of certain fields. This customization is provided via a class that implements the TypeAugmenter interface. The editor will query additional information for every field via this interface. Currently, a field can be augmented by providing a help text and a style IntEnum. The help text will be shown in the tooltip of each field and the style flag modifies the way how a field is displayed. A field can be hidden or be declared as read-only.

The editor comes with a default implementation of this augmenter that uses a .style file to customize the way fields are displayed in asn1editor.

If an ASN.1 file is opened, asn1editor looks for an equally named file with a .style extension in the same directory. If it is found, it is loaded and used to refine the layout of the specification. A style file is in JSON format and contains the name of the ASN.1 field as a key, and the layout specifier as value. The specifiers are named "read_only" and "hidden".

Example:

{
"firstField": "read_only",
"secondField": "hidden"
}

Tests

Apart from unit tests in the source folder, there is a project on testquality.com that contains a number of manual tests to qualify an asn1editor release here. You can log in using the credentials [email protected]/readonly to view the test cases and test results.

asn1editor's People

Contributors

futsch1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

asn1editor's Issues

Highlighting constraints violations is not reset after loading

Precondition

Launch the application with the arguments "example/example.asn -type EXAMPLE.Sequence"
Switch tool to Tree view

Steps to Reproduce:

Step Action Expected Status
1 Select Sequence->example1, set member1 to 999

Save encoded data
No error Pass
2 Set member1 to 6000

Select Sequence->example2

Select Sequence->example1

Save encoded data

Load encoded data
After reselection, member1 is highlighted

Saving fails with error: "example1: member1: Expected an integer between 0 and 5000, but got 6000."

After loading, member1 has the value 999
Value is 999, but the highlighting is not reset
3 Hover over Sequence->example1 Tooltip "Minimum:0, Maximum: 5000" is shown Pending

[Views] Tree view - Fail

Precondition

Launch the application with the arguments "example/example.asn -type EXAMPLE.Sequence"
Switch tool to Tree view

Steps to Reproduce:

Step Action Expected Status
1 Select Sequence Sequence members are displayed in content view (right side)

Only "trivial" types (not sequence, choice, sequence of) are displayed
Pass
2 Select example1 Only members of sequence example1 are displayed in content view Pass
3 Select optionalSequenceOf

Enable optionalSequenceOf

Increase elements to 2

Select both elements

Decrease elements to 1
Correct number of elements are displayed at all times as children of optionalSequenceOf

Members of elements are displayed in content view when selected
Pass
4 Select choiceExample

Select all possible values of choiceExample
Child of choiceExample always reflects the choice selection

Child contents always reflect child type
Pass
5 Right click choiceExample

Choose Collapse
choiceExample node is collapsed, child is no longer visible in tree Pass
6 Right click choiceExample

Choose Expand
Child is visible in tree Pass
7 Right click sequence

Choose Collapse all
Only the root of tree is visible Fail
8 Right click sequence

Choose Expand all
All tree items are visible Fail

When collapsing all, the root node is selected. However, in the content panel, the previous content is displayed. This should be reset to an empty panel.

Restoring directory does not work for DirDialog

File "C:\DATEN\Projects\OER_working_branch\src\euchnerDataFileTools\asn1editor\wxPython\FilePickerHandler.py", line 22, in on_menu_click
file_dialog.SetDirectory(initial_dir)
AttributeError: 'DirDialog' object has no attribute 'SetDirectory'

[Plugins] File and dir dialogs - Fail

Steps to Reproduce:

Step Action Expected Status
1 Start the application with the "-test" argument

Open "Test->FileDialog"

Select an existing file to open

Select an existing file to save and overwrite
An open file dialog is shown with the caption "Test open file"

Selected file is shown in the tool's status bar

A save file dialog is shown with the caption "Test save file"

A popup is shown asking to overwrite the file

Selected file is shown in the tool's status bar
Pass
2 Open "Test 2->DirDialog" and select a directory

Open "Test->DirDialog" and select a different directory with a different parent directory
A directory select dialog is shown with the caption "Test 2"

The selected directory is shown in the tool's status bar

A directory select dialog is shown with the caption "Test"

The selected directory is shown in the tool's status bar
Fail

Error:

When selecting a directory, the application crashes:
File "C:\Users\Flo\Documents\Programmieren\asn1editor\asn1editor\wxPython\FilePickerHandler.py", line 26, in on_menu_click
filenames = file_dialog.GetPaths()
AttributeError: 'DirDialog' object has no attribute 'GetPaths'

Additionals default value

Open example.asn, enable ...additionalOptional. Enter value 2. Load example.json.

Expected: ...additionalOptional is reset to default
Observed: value 2 stays

[Main functionality] Load last specification - Fail

Precondition

Setting "Open last specification on startup" is disabled

Steps to Reproduce:

Step Action Expected Status
1 Open the application

Enable the setting "Open last specification on startup"

Open the example.asn specification, type "EXAMPLE.Sequence"

Close the application

Open the application
After reopen, the example.asn is opened with the type "EXAMPLE.Sequence" Fail

Error

Not necessarily the most recent file is opened if this file is already in the "Recent" list. In this case, the uppermost entry of the "Recent" list is loaded.

[Views] Tree view - Fail

Precondition

Launch the application with the arguments "example/example.asn -type EXAMPLE.Sequence"
Switch tool to Tree view

Steps to Reproduce:

Step Action Expected Status
1 Select Sequence Sequence members are displayed in content view (right side)

Only "trivial" types (not sequence, choice, sequence of) are displayed
Pass
2 Select example1 Only members of sequence example1 are displayed in content view Pass
3 Select optionalSequenceOf

Enable optionalSequenceOf

Increase elements to 2

Select both elements

Decrease elements to 1
Correct number of elements are displayed at all times as children of optionalSequenceOf

Members of elements are displayed in content view when selected
Pass
4 Select choiceExample

Select all possible values of choiceExample
Child of choiceExample always reflects the choice selection

Child contents always reflect child type
Pass
5 Right click choiceExample

Choose Collapse
choiceExample node is collapsed, child is no longer visible in tree Fail
6 Right click choiceExample

Choose Expand
Child is visible in tree Fail
7 Right click sequence

Choose Collapse all
Only the root of tree is visible Fail
8 Right click sequence

Choose Expand all
All tree items are visible Fail

Right clicking an element does not change the content panel, but it should.

[Main functionality] Open recent - Fail

Steps to Reproduce:

Step Action Expected Status
1 Open the application

Open the example.asn specification, type "EXAMPLE.Sequence"

Open File->Open recent
example.asn, type "EXAMPLE.Sequence" is in the recent list Pass
2 Close the application

Open the application
example.asn, type "EXAMPLE.Sequence" is in the recent list Pass
3 Clear the recent list

Close the application

Open the application
The recent list is empty Fail

Error:

When clearing the recent list, a deprecated warning appears:
C:\Users\Flo\Documents\Programmieren\asn1editor\asn1editor\wxPython\MenuHandler.py:172: wxPyDeprecationWarning: Call to deprecated item. Use Remove instead.
self.__recent_menu.RemoveItem(menu_item)

[Main functionality] Open recent - Fail

Steps to Reproduce:

Step Action Expected Status
1 Open the application

Open the example.asn specification, type "EXAMPLE.Sequence"

Open File->Open recent
example.asn, type "EXAMPLE.Sequence" is in the recent list Pass
2 Close the application

Open the application
example.asn, type "EXAMPLE.Sequence" is in the recent list Pass
3 Clear the recent list

Close the application

Open the application
The recent list is empty Fail

Error:

After reopening the application, no specification was opened although open last specification was checked and a specification was loaded while closing the application.

[UI elements] Strings - Fail

Precondition

Launch the application with the arguments "-asn1spec example/example.asn -type EXAMPLE.Sequence"
Switch tool to Tree view

Steps to Reproduce:

Step Action Expected Status
1 Select Sequence

Set visibleString to "hello"

Save data file

Set visibleString to "goodbye"

Load data file
Visible string is restored to "hello" Pass
2 Try to put more than 15 characters into visibleString Not more than 15 characters can be entered Pass
3 Hover the mouse over visibleString Tooltip is displayed: "Minimum characters: 0, maximum characters: 15" Pass
4 Set utf8String to "" (empty string)

Save data file

Set utf8String to "äöüØ"

Save data file

Set utf8String to "1"

Load data file
First save yields an error: "utf8String: Expected between 1 and 5 characters, but got 0."

Second save is ok.

After loading, utf8String is restored to "äöüØ"
Pass
5 Disable "Hex" checkbox for octet string

Set octet string to "ab"

Save data file

Set octet string to "ffff"

Save data file

Set octet string to "abcd"

Load data file
First save yields an error: "octetString: Expected between 4 and 4 characters, but got 2."

Second save is ok.

After loading, octetString is restored to "ffff"
Pass
6 Set octet string to "abcd"

Enable "Hex" checkbox for octet string

Enter "64 63 62 61"

Disable "Hex" checkbox for octet string

Enable "Hex" checkbox for octet string

Enter "uu"

Disable "Hex" checkbox for octet string
Enabling "Hex" checkbox shows "61 62 63 64"

Disabling "Hex" checkbox shows "dcba"

Enabling "Hex" checkbox shows "64 63 62 61"

Disabling "Hex" checkbox shows "dcba"
Fail

Error:

When in Hex view, the maximum number of characters is incorrect. It is two times the string length, but should be three times the string length (two chars + space).

[Plugins] File and dir dialogs - Fail

Steps to Reproduce:

Step Action Expected Status
1 Start the application with the "-test" argument

Open "Test->FileDialog"

Select an existing file to open

Select an existing file to save and overwrite
An open file dialog is shown with the caption "Test open file"

Selected file is shown in the tool's status bar

A save file dialog is shown with the caption "Test save file"

A popup is shown asking to overwrite the file

Selected file is shown in the tool's status bar
Pass
2 Open "Test 2->DirDialog" and select a directory

Open "Test->DirDialog" and select a different directory with a different parent directory
A directory select dialog is shown with the caption "Test 2"

The selected directory is shown in the tool's status bar

A directory select dialog is shown with the caption "Test"

The selected directory is shown in the tool's status bar
Pass
3 Close the application

Start the application with the "-test" argument

Open "Test 2->DirDialog" and cancel

Open "Test->DirDialog" and cancel
Start directory of "Test 2" dialog is the same as in step 2

Start directory of "Test" dialog is the same as in step 2
Fail

Directory in the opened dir dialog is one level further up than expected.

[Main functionality] Drag & drop - Fail

Precondition

Launch the application without arguments, close potentially open specifications

Steps to Reproduce:

Step Action Expected Status
1 Drag the file example/example.asn to the main window

Select Sequence type
Dialog box for selecting a type appears

Specification is loaded
Fail

The dialog box appears, but in the wrong GUI state. The GUI is locked in that state and the drop cursor is still shown. The dialog box should appear after the file has been dropped and the event has benn processed.

[Main functionality] Load last specification - Fail

Precondition

Setting "Open last specification on startup" is disabled

Steps to Reproduce:

Step Action Expected Status
1 Open the application

Enable the setting "Open last specification on startup"

Open the example.asn specification, type "EXAMPLE.Sequence"

Close the application

Open the application
After reopen, the example.asn is opened with the type "EXAMPLE.Sequence" Pass
2 Open "tests/standards/rfc1157.asn", type RFC1157-SNMP.Message

Close the application

Open the application
After reopen, "tests/standards/rfc1157.asn" with type RFC1157-SNMP.Message is opened Pass
3 Close the specification

Close the application

Open the application
After reopen, no specification is loaded Fail
4 Open "tests/standards/rfc1157.asn", type RFC1157-SNMP.Message

Disable the setting "Open last specification on startup"

Close the application

Open the application
After reopen, no specification is loaded Fail

Error:

After reopening, the specification rfc1157.asn was loaded again.

[UI elements] Strings - Fail

Precondition

Launch the application with the arguments "example/example.asn -type EXAMPLE.Sequence"
Switch tool to Tree view

Steps to Reproduce:

Step Action Expected Status
1 Select Sequence

Set visibleString to "hello"

Save encoded data

Set visibleString to "goodbye"

Load encoded data
Visible string is restored to "hello" Pass
2 Try to put more than 15 characters into visibleString Not more than 15 characters can be entered Pass
3 Hover the mouse over visibleString Tooltip is displayed: "Minimum characters: 0, maximum characters: 15" Pass
4 Set utf8String to "" (empty string)

Save data file

Set utf8String to "äöüØ"

Save data file

Set utf8String to "1"

Load data file
First save yields an error: "utf8String: Expected between 1 and 5 characters, but got 0."

Second save is ok.

After loading, utf8String is restored to "äöüØ"
Pass
5 Disable "Hex" checkbox for octet string

Set octet string to "ab"

Save data file

Set octet string to "ffff"

Save data file

Set octet string to "abcd"

Load data file
First save yields an error: "octetString: Expected between 4 and 4 characters, but got 2."

Second save is ok.

After loading, octetString is restored to "ffff"
Fail
6 Set octet string to "abcd"

Enable "Hex" checkbox for octet string

Enter "64 63 62 61"

Disable "Hex" checkbox for octet string

Enable "Hex" checkbox for octet string

Enter "uu"

Disable "Hex" checkbox for octet string
Enabling "Hex" checkbox shows "61 62 63 64"

Disabling "Hex" checkbox shows "dcba"

Enabling "Hex" checkbox shows "64 63 62 61"

Disabling "Hex" checkbox shows "dcba"
Fail

Actual Results:

Octet string length is only 1 after disabling hex checkbox

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.