Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Exchange the InputStream(Encryption on low level)
Exchange the InputStream [message #917646] Thu, 20 September 2012 09:34 Go to next message
Moritz Höser is currently offline Moritz HöserFriend
Messages: 11
Registered: September 2012
Junior Member
Hi,
I have read about registering an own lexer and more for your language, so I wonder if the following is also possible:
Decrypt a file with a simple encryption algorithm (e.g. Caesar cipher) while reading, and encrypting it again while writing. So far I work on a temporary copy of the decrypted file in the IDE, and write it back encrypted on save.

Is it possible to exchange e.g. the InputStream that Xtext uses with a class that does some kind of manipulation on the bytes read? Which binding in the RuntimeModule would have to be changed?

The benefit would be that the encryption is very transparent.
Thank you very much for every help!
Re: Exchange the InputStream [message #918220 is a reply to message #917646] Thu, 20 September 2012 21:21 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-20-09 11:34, Moritz Höser wrote:
> Hi,
> I have read about registering an own lexer and more for your language,
> so I wonder if the following is also possible:
> Decrypt a file with a simple encryption algorithm (e.g. Caesar cipher)
> while reading, and encrypting it again while writing. So far I work on a
> temporary copy of the decrypted file in the IDE, and write it back
> encrypted on save.
>
> Is it possible to exchange e.g. the InputStream that Xtext uses with a
> class that does some kind of manipulation on the bytes read? Which
> binding in the RuntimeModule would have to be changed?
>
> The benefit would be that the encryption is very transparent.
> Thank you very much for every help!

I use an external lexer in cloudsmith/geppetto @ github and the external
lexer is wrapped in a special class as well. You can take a look at that
logic and how it is bound.

Remember that the lexer is also invoked also for parsing partial input.

Hope that helps.
Regards
- henrik
Re: Exchange the InputStream [message #924340 is a reply to message #917646] Wed, 26 September 2012 19:14 Go to previous messageGo to next message
Moritz Höser is currently offline Moritz HöserFriend
Messages: 11
Registered: September 2012
Junior Member
Thank you Henrik!

I looked into it and what I learned was that I don't want to extend the Lexer, but the Source of the CharStream.
In case of using an UI Editor, the lexers CharStream (Antlr) is an ANTLRStringStream which gets its String input from DocumentTokenSource (Xtext), which in turn gets the content of the IDocument (JFace) one is working on in the editor:
-> Change/Load Event (UI) -> XtextDocument -> DocumentTokenSource.createLexer(String) -> ANTLRStringStream

Since I only need to decrypt/encrypt the file on load/save, I only need to change the way the Documents ITextStore is read/written. This would be the point to handle the encryption, and admittedly, it has nothing to do with Xtext directly (correct?).

I hope I can somehow reuse the code for the case when the file is loaded in a standalone application.
Re: Exchange the InputStream [message #924754 is a reply to message #924340] Thu, 27 September 2012 05:19 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Sounds like you want to cut into the process where an IResource is being
read. I wonder if it would perhaps best be implemented as an Eclipse
File System where files can be encrypted. That would make it completely
transparent to all upper layers. This way even a simple text editor
could open an encrypted file.

Regards
- henrik

On 2012-26-09 12:14, Moritz Höser wrote:
> Thank you Henrik!
>
> I looked into it and what I learned was that I don't want to extend the
> Lexer, but the Source of the CharStream.
> In case of using an UI Editor, the lexers CharStream (Antlr) is an
> ANTLRStringStream which gets its String input from DocumentTokenSource
> (Xtext), which in turn gets the content of the IDocument (JFace) one is
> working on in the editor:
> -> Change/Load Event (UI) -> XtextDocument ->
> DocumentTokenSource.createLexer(String) -> ANTLRStringStream
>
> Since I only need to decrypt/encrypt the file on load/save, I only need
> to change the way the Documents ITextStore is read/written. This would
> be the point to handle the encryption, and admittedly, it has nothing to
> do with Xtext directly (correct?).
>
> I hope I can somehow reuse the code for the case when the file is loaded
> in a standalone application.
Re: Exchange the InputStream [message #925379 is a reply to message #924754] Thu, 27 September 2012 17:05 Go to previous messageGo to next message
Moritz Höser is currently offline Moritz HöserFriend
Messages: 11
Registered: September 2012
Junior Member
Great, I think the EFS is exactly what I was looking for, thank you.

I wrote a FileStore for this purpose (providing a custom InputStream), but I don't know how to register it properly. If I use a new FileSystem, it will only be activated when the file uri has a special scheme. I want to use the "file:" scheme, so that a simple double click opens an editor with the decrypted file, as you suggested.

In case someone is looking for a solution, I opened another topic since this is not directly Xtext

Henrik Lindberg wrote on Thu, 27 September 2012 01:19
Sounds like you want to cut into the process where an IResource is being
read. I wonder if it would perhaps best be implemented as an Eclipse
File System where files can be encrypted. That would make it completely
transparent to all upper layers. This way even a simple text editor
could open an encrypted file.

Re: Exchange the InputStream [message #925444 is a reply to message #925379] Thu, 27 September 2012 18:18 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-27-09 10:05, Moritz Höser wrote:
> Great, I think the EFS is exactly what I was looking for, thank you.
>
> I wrote a FileStore for this purpose (providing a custom InputStream),
> but I don't know how to register it properly. If I use a new FileSystem,
> it will only be activated when the file uri has a special scheme. I want
> to use the "file:" scheme, so that a simple double click opens an editor
> with the decrypted file, as you suggested.
>
> In case someone is looking for a solution, I opened
> http://www.eclipse.org/forums/index.php/t/386177/ since this is not
> directly Xtext
>
> Henrik Lindberg wrote on Thu, 27 September 2012 01:19
>> Sounds like you want to cut into the process where an IResource is
>> being read. I wonder if it would perhaps best be implemented as an
>> Eclipse File System where files can be encrypted. That would make it
>> completely transparent to all upper layers. This way even a simple
>> text editor could open an encrypted file.
>
>
Replace the file scheme with a delegating scheme ?

- henrik
Re: Exchange the InputStream [message #925732 is a reply to message #925444] Fri, 28 September 2012 01:27 Go to previous messageGo to next message
Moritz Höser is currently offline Moritz HöserFriend
Messages: 11
Registered: September 2012
Junior Member
I think you suggest to change the files locationUri. This may be possible for single files if done by hand, but to keep track of all the ways a file can be created and change its uri programmatically seems like an awful lot of work to me.. And when the root folder of a file is a linked, non-virtual folder, its not possible to change the file scheme. So if I see it right, when one want to use the standard Project Explorer and so on, a custom FileStore must be provided with the "file" filesystem (aka LocalFileSystem).

To see if it works, I registered a FileSystem to the scheme "file" which provides FileStores that are fully compatible with the usually ones but open special InputStreams for the encrypted file types. This works, Xtext loads the encypted files and displays the decrypted text, and saves the text encrypted again without any other modifications. But it is rather ugly, since having a second "file" FileSystem is not intended.

I will try to work with a special charset / Encoding instead.

If someone has any other ideas or remarks, please let me know.

Henrik Lindberg wrote on Thu, 27 September 2012 14:18
Replace the file scheme with a delegating scheme ?

- henrik

Thank you for your help Henrik.
Re: Exchange the InputStream [message #949201 is a reply to message #925732] Thu, 18 October 2012 19:59 Go to previous message
Michael Remme is currently offline Michael RemmeFriend
Messages: 9
Registered: October 2012
Junior Member
hi Henrik,

probably its too late for your solution. I had the same problem today and found the solution in the Platform Plugin developer guide. You will have to create another extension point like this:

<extension
point="org.eclipse.ui.ide.filesystemSupport">
<filesystemContributor
class="de.braintags.filesystem.NetRelayFileSystemContributor"
label="NetRelay file system (nrfs )"
scheme="nrfs">
</filesystemContributor>
</extension>

where the class is extending org.eclipse.ui.ide.fileSystem.FileSystemContributor

After you did that, start your plugin and call File -> New -> File. Then you open the advanced part, activate "link to file into the file system", open the select box at "Choose file system" and you will be able to choose your filesystem definition - in my case there is now displayed "NetRelay file system ( nrfs)"

regards,
Mike
Previous Topic:Re: Couple Graphiti Editor with XText DSL
Next Topic:alternate between assignment and terminal
Goto Forum:
  


Current Time: Tue Sep 29 21:31:59 GMT 2020

Powered by FUDForum. Page generated in 0.02422 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top