This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Exception doesn't fit source  RSS feed

Ranch Hand
Posts: 113
MS IE Notepad Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I was playing around a bit with BouncyCastle - and got an Exception wich shouldn't happen according to source.

What I tried:

When checking privateKey.getClass().getName() I get com.sun.crypto.provider.DHPrivateKey. But last line throws this Stacktrace:

So I dug through the code - here is what gets called in order:





As far as I understand this whole if-mess in createPemObject the Exception throw should only happen if the passed Object is instanceof org.bouncycastle.asn1.pkcs.PrivateKeyInfo - wich com.sun.crypto.provider.DHPrivateKey obviously isn't. Am I don't getting the right path and get trolled by indentation?
So, I re-indented the code with the missing parenthesis after each else - this is what I came up with:

Is this the real truth table - or am I mis-understanding "else if" and this should better be placed in beginners forum?

As far as I understand blocks with optional parenthesis:

As the last statement line is also another if - it cascades down to:

Am I right with this - or is it here why I think the line "unknown object passed - can't encode." should be thrown? Or did someone at BouncyCastle missed some parenthesis somewhere so the flow is different from what the dev might thought it would be?

Also: THAT'S the reason why one should never omit parenthesis even if it's allowed.

I just don't understand how the flow ends in "Cannot identify private key" when, as far as I understand it, to end up there Object needs to be instanceof PrivateKeyInfo.

I also had it run through de-compiler - here's the output:

So, to get to the Exception "Cannot identify private key" Object indeed has to be instanceof PrivateKeyInfo - wich com.sun.crypto.provider.DHPrivateKey neither is nor could - I'm not seeing it ...
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!